Index: llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp +++ llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp @@ -4832,6 +4832,15 @@ case PPC::PRED_NE: Opc = PPC::CRXOR; Swap = false; break; } + // A signed comparison of i1 values produces the opposite result to an + // unsigned one if the condition code includes less-than or greater-than. + // This is because 1 is the most negative signed i1 number and the most + // positive unsigned i1 number. The CR-logical operations used for such + // comparisons are non-commutative so for signed comparisons vs. unsigned + // ones, the input operands just need to be swapped. + if (ISD::isSignedIntSetCC(CC)) + Swap = !Swap; + SDValue BitComp(CurDAG->getMachineNode(Opc, dl, MVT::i1, N->getOperand(Swap ? 3 : 2), N->getOperand(Swap ? 2 : 3)), 0); Index: llvm/test/CodeGen/PowerPC/brcond.ll =================================================================== --- llvm/test/CodeGen/PowerPC/brcond.ll +++ llvm/test/CodeGen/PowerPC/brcond.ll @@ -3,7 +3,7 @@ define signext i32 @testi32slt(i32 signext %c1, i32 signext %c2, i32 signext %c3, i32 signext %c4, i32 signext %a1, i32 signext %a2) #0 { ; CHECK-LABEL: testi32slt -; CHECK: crorc [[REG1:[0-9]+]], 6, 2 +; CHECK: crorc [[REG1:[0-9]+]], 2, 6 entry: %cmp1 = icmp eq i32 %c3, %c4 %cmp3tmp = icmp eq i32 %c1, %c2 @@ -31,7 +31,7 @@ define signext i32 @testi32sle(i32 signext %c1, i32 signext %c2, i32 signext %c3, i32 signext %c4, i32 signext %a1, i32 signext %a2) #0 { ; CHECK-LABEL: testi32sle -; CHECK: crandc [[REG1:[0-9]+]], 6, 2 +; CHECK: crandc [[REG1:[0-9]+]], 2, 6 entry: %cmp1 = icmp eq i32 %c3, %c4 %cmp3tmp = icmp eq i32 %c1, %c2 @@ -73,7 +73,7 @@ define signext i32 @testi32sge(i32 signext %c1, i32 signext %c2, i32 signext %c3, i32 signext %c4, i32 signext %a1, i32 signext %a2) #0 { ; CHECK-LABEL: testi32sge: -; CHECK: crandc [[REG1:[0-9]+]], 2, 6 +; CHECK: crandc [[REG1:[0-9]+]], 6, 2 entry: %cmp1 = icmp eq i32 %c3, %c4 %cmp3tmp = icmp eq i32 %c1, %c2 @@ -101,7 +101,7 @@ define signext i32 @testi32sgt(i32 signext %c1, i32 signext %c2, i32 signext %c3, i32 signext %c4, i32 signext %a1, i32 signext %a2) #0 { ; CHECK-LABEL: testi32sgt: -; CHECK: crorc [[REG1:[0-9]+]], 2, 6 +; CHECK: crorc [[REG1:[0-9]+]], 6, 2 entry: %cmp1 = icmp eq i32 %c3, %c4 %cmp3tmp = icmp eq i32 %c1, %c2 @@ -143,7 +143,7 @@ define i64 @testi64slt(i64 %c1, i64 %c2, i64 %c3, i64 %c4, i64 %a1, i64 %a2) #0 { ; CHECK-LABEL: testi64slt -; CHECK: crorc [[REG1:[0-9]+]], 6, 2 +; CHECK: crorc [[REG1:[0-9]+]], 2, 6 entry: %cmp1 = icmp eq i64 %c3, %c4 %cmp3tmp = icmp eq i64 %c1, %c2 @@ -171,7 +171,7 @@ define i64 @testi64sle(i64 %c1, i64 %c2, i64 %c3, i64 %c4, i64 %a1, i64 %a2) #0 { ; CHECK-LABEL: testi64sle -; CHECK: crandc [[REG1:[0-9]+]], 6, 2 +; CHECK: crandc [[REG1:[0-9]+]], 2, 6 entry: %cmp1 = icmp eq i64 %c3, %c4 %cmp3tmp = icmp eq i64 %c1, %c2 @@ -213,7 +213,7 @@ define i64 @testi64sge(i64 %c1, i64 %c2, i64 %c3, i64 %c4, i64 %a1, i64 %a2) #0 { ; CHECK-LABEL: testi64sge -; CHECK: crandc [[REG1:[0-9]+]], 2, 6 +; CHECK: crandc [[REG1:[0-9]+]], 6, 2 entry: %cmp1 = icmp eq i64 %c3, %c4 %cmp3tmp = icmp eq i64 %c1, %c2 @@ -241,7 +241,7 @@ define i64 @testi64sgt(i64 %c1, i64 %c2, i64 %c3, i64 %c4, i64 %a1, i64 %a2) #0 { ; CHECK-LABEL: testi64sgt -; CHECK: crorc [[REG1:[0-9]+]], 2, 6 +; CHECK: crorc [[REG1:[0-9]+]], 6, 2 entry: %cmp1 = icmp eq i64 %c3, %c4 %cmp3tmp = icmp eq i64 %c1, %c2 @@ -283,7 +283,7 @@ define float @testfloatslt(float %c1, float %c2, float %c3, float %c4, float %a1, float %a2) #0 { ; CHECK-LABEL: testfloatslt -; CHECK: crorc [[REG1:[0-9]+]], 6, 2 +; CHECK: crorc [[REG1:[0-9]+]], 2, 6 entry: %cmp1 = fcmp oeq float %c3, %c4 %cmp3tmp = fcmp oeq float %c1, %c2 @@ -311,7 +311,7 @@ define float @testfloatsle(float %c1, float %c2, float %c3, float %c4, float %a1, float %a2) #0 { ; CHECK-LABEL: testfloatsle -; CHECK: crandc [[REG1:[0-9]+]], 6, 2 +; CHECK: crandc [[REG1:[0-9]+]], 2, 6 entry: %cmp1 = fcmp oeq float %c3, %c4 %cmp3tmp = fcmp oeq float %c1, %c2 @@ -353,7 +353,7 @@ define float @testfloatsge(float %c1, float %c2, float %c3, float %c4, float %a1, float %a2) #0 { ; CHECK-LABEL: testfloatsge -; CHECK: crandc [[REG1:[0-9]+]], 2, 6 +; CHECK: crandc [[REG1:[0-9]+]], 6, 2 entry: %cmp1 = fcmp oeq float %c3, %c4 %cmp3tmp = fcmp oeq float %c1, %c2 @@ -381,7 +381,7 @@ define float @testfloatsgt(float %c1, float %c2, float %c3, float %c4, float %a1, float %a2) #0 { ; CHECK-LABEL: testfloatsgt -; CHECK: crorc [[REG1:[0-9]+]], 2, 6 +; CHECK: crorc [[REG1:[0-9]+]], 6, 2 entry: %cmp1 = fcmp oeq float %c3, %c4 %cmp3tmp = fcmp oeq float %c1, %c2 @@ -423,7 +423,7 @@ define double @testdoubleslt(double %c1, double %c2, double %c3, double %c4, double %a1, double %a2) #0 { ; CHECK-LABEL: testdoubleslt -; CHECK: crorc [[REG1:[0-9]+]], 6, 2 +; CHECK: crorc [[REG1:[0-9]+]], 2, 6 entry: %cmp1 = fcmp oeq double %c3, %c4 %cmp3tmp = fcmp oeq double %c1, %c2 @@ -451,7 +451,7 @@ define double @testdoublesle(double %c1, double %c2, double %c3, double %c4, double %a1, double %a2) #0 { ; CHECK-LABEL: testdoublesle -; CHECK: crandc [[REG1:[0-9]+]], 6, 2 +; CHECK: crandc [[REG1:[0-9]+]], 2, 6 entry: %cmp1 = fcmp oeq double %c3, %c4 %cmp3tmp = fcmp oeq double %c1, %c2 @@ -493,7 +493,7 @@ define double @testdoublesge(double %c1, double %c2, double %c3, double %c4, double %a1, double %a2) #0 { ; CHECK-LABEL: testdoublesge -; CHECK: crandc [[REG1:[0-9]+]], 2, 6 +; CHECK: crandc [[REG1:[0-9]+]], 6, 2 entry: %cmp1 = fcmp oeq double %c3, %c4 %cmp3tmp = fcmp oeq double %c1, %c2 @@ -521,7 +521,7 @@ define double @testdoublesgt(double %c1, double %c2, double %c3, double %c4, double %a1, double %a2) #0 { ; CHECK-LABEL: testdoublesgt: -; CHECK: crorc [[REG1:[0-9]+]], 2, 6 +; CHECK: crorc [[REG1:[0-9]+]], 6, 2 entry: %cmp1 = fcmp oeq double %c3, %c4 %cmp3tmp = fcmp oeq double %c1, %c2