Merging r259375:
authorHans Wennborg <hans@hanshq.net>
Mon, 1 Feb 2016 19:18:10 +0000 (19:18 +0000)
committerHans Wennborg <hans@hanshq.net>
Mon, 1 Feb 2016 19:18:10 +0000 (19:18 +0000)
------------------------------------------------------------------------
r259375 | majnemer | 2016-02-01 09:37:56 -0800 (Mon, 01 Feb 2016) | 6 lines

[InstCombine] Don't transform (X+INT_MAX)>=(Y+INT_MAX) -> (X<=Y)

This miscompile came about because we tried to use a transform which was
only appropriate for xor operators when addition was present.

This fixes PR26407.
------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_38@259390 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp.ll

index c0786afe965ee4e626d4118360c559baa9749755..d9311a343eadb57fdcfd9d02a592e91985335a31 100644 (file)
@@ -3560,7 +3560,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
                                 BO1->getOperand(0));
           }
 
-          if (CI->isMaxValue(true)) {
+          if (BO0->getOpcode() == Instruction::Xor && CI->isMaxValue(true)) {
             ICmpInst::Predicate Pred = I.isSigned()
                                            ? I.getUnsignedPredicate()
                                            : I.getSignedPredicate();
index 7d6ec96b53282e21f7f0610091afc7a5b6b849ca..1e64cd7f58207adc52a09fecc4f3ba52baf1e79f 100644 (file)
@@ -1672,3 +1672,15 @@ define i1 @cmp_slt_rhs_inc(float %x, i32 %i) {
   %cmp = icmp slt i32 %conv, %inc
   ret i1 %cmp
 }
+
+; CHECK-LABEL: @PR26407
+; CHECK-NEXT: %[[addx:.*]] = add i32 %x, 2147483647
+; CHECK-NEXT: %[[addy:.*]] = add i32 %y, 2147483647
+; CHECK-NEXT: %[[cmp:.*]] = icmp uge i32 %[[addx]], %[[addy]]
+; CHECK-NEXT: ret i1 %[[cmp]]
+define i1 @PR26407(i32 %x, i32 %y) {
+  %addx = add i32 %x, 2147483647
+  %addy = add i32 %y, 2147483647
+  %cmp = icmp uge i32 %addx, %addy
+  ret i1 %cmp
+}