]> granicus.if.org Git - llvm/commitdiff
GlobalISel: select G_BRCOND instructions on AArch64.
authorTim Northover <tnorthover@apple.com>
Wed, 12 Oct 2016 22:49:01 +0000 (22:49 +0000)
committerTim Northover <tnorthover@apple.com>
Wed, 12 Oct 2016 22:49:01 +0000 (22:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284071 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AArch64/AArch64InstructionSelector.cpp
test/CodeGen/AArch64/GlobalISel/arm64-instructionselect.mir

index d9d24779a1833511f934e5fa1db6b07944923ce7..5be437d610be5d71b29eae0110e8f99b2db3d4cb 100644 (file)
@@ -299,6 +299,28 @@ bool AArch64InstructionSelector::select(MachineInstr &I) const {
     return true;
   }
 
+  case TargetOpcode::G_BRCOND: {
+    if (Ty.getSizeInBits() > 32) {
+      // We shouldn't need this on AArch64, but it would be implemented as an
+      // EXTRACT_SUBREG followed by a TBNZW because TBNZX has no encoding if the
+      // bit being tested is < 32.
+      DEBUG(dbgs() << "G_BRCOND has type: " << Ty
+                   << ", expected at most 32-bits");
+      return false;
+    }
+
+    const unsigned CondReg = I.getOperand(0).getReg();
+    MachineBasicBlock *DestMBB = I.getOperand(1).getMBB();
+
+    auto MIB = BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::TBNZW))
+                   .addUse(CondReg)
+                   .addImm(/*bit offset=*/0)
+                   .addMBB(DestMBB);
+
+    I.eraseFromParent();
+    return constrainSelectedInstRegOperands(*MIB.getInstr(), TII, TRI, RBI);
+  }
+
   case TargetOpcode::G_CONSTANT: {
     if (Ty.getSizeInBits() <= 32)
       I.setDesc(TII.get(AArch64::MOVi32imm));
index 3f1d11d0b3a5254b784825690fb7e92c24b141cb..57a52bf3107941b76fb94d8f4598d9fb7689d966 100644 (file)
@@ -54,6 +54,7 @@
   define void @fdiv_s64_gpr() { ret void }
 
   define void @unconditional_br() { ret void }
+  define void @conditional_br() { ret void }
 
   define void @load_s64_gpr(i64* %addr) { ret void }
   define void @load_s32_gpr(i32* %addr) { ret void }
@@ -1012,6 +1013,29 @@ body:             |
     G_BR %bb.0
 ...
 
+---
+# CHECK-LABEL: name: conditional_br
+name:            conditional_br
+legalized:       true
+regBankSelected: true
+
+registers:
+  - { id: 0, class: gpr }
+
+# CHECK:  body:
+# CHECK:   bb.0:
+# CHECK:    TBNZW %0, 0, %bb.1
+# CHECK:    B %bb.0
+body:             |
+  bb.0:
+    successors: %bb.0, %bb.1
+    %0(s1) = COPY %w0
+    G_BRCOND %0(s1), %bb.1
+    G_BR %bb.0
+
+  bb.1:
+...
+
 ---
 # CHECK-LABEL: name: load_s64_gpr
 name:            load_s64_gpr