be layout aware, to produce:
authorChris Lattner <sabre@nondot.org>
Tue, 19 Apr 2011 04:26:32 +0000 (04:26 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 19 Apr 2011 04:26:32 +0000 (04:26 +0000)
testb $1, %al
je LBB0_2
## BB#1:                                ## %if.then
movb $0, %al

instead of:

testb $1, %al
jne LBB0_1
jmp LBB0_2
LBB0_1:                                 ## %if.then
movb $0, %al

how 'bout that.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129749 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86FastISel.cpp
test/CodeGen/X86/fast-isel-x86-64.ll

index 2c92961452912f80a3a0e800877d59b3b40a166c..77e67a1740c80d2ac333e33c3590e945c04bd09e 100644 (file)
@@ -1084,7 +1084,14 @@ bool X86FastISel::X86SelectBranch(const Instruction *I) {
         if (OpReg == 0) return false;
         BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TestOpc))
           .addReg(OpReg).addImm(1);
-        BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(X86::JNE_4))
+        
+        unsigned JmpOpc = X86::JNE_4;
+        if (FuncInfo.MBB->isLayoutSuccessor(TrueMBB)) {
+          std::swap(TrueMBB, FalseMBB);
+          JmpOpc = X86::JE_4;
+        }
+        
+        BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(JmpOpc))
           .addMBB(TrueMBB);
         FastEmitBranch(FalseMBB, DL);
         FuncInfo.MBB->addSuccessor(TrueMBB);
index fe8530ca2962e792181c8f654edf6c6b861705a7..0c289e37975392e78773dff8e31d74c14eb96aa0 100644 (file)
@@ -142,5 +142,7 @@ if.end:                                           ; preds = %if.then, %entry
   ret void
 ; CHECK: test12:
 ; CHECK: testb $1,
+; CHECK-NEXT: je L
+; CHECK-NEXT: movb     $0, %al
 }