[llvm] r239139 - Revert "[InstCombine] Don't miscompile safe increment idiom"

Daniel Jasper djasper at google.com
Fri Jun 5 02:31:20 PDT 2015


Author: djasper
Date: Fri Jun  5 04:31:20 2015
New Revision: 239139

URL: http://llvm.org/viewvc/llvm-project?rev=239139&view=rev
Log:
Revert "[InstCombine] Don't miscompile safe increment idiom"

This is breaking a lot of build bots and is causing very long-running
compiles (infinite loops)?

Likely, we shouldn't return nullptr?

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
    llvm/trunk/test/Transforms/InstCombine/select.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=239139&r1=239138&r2=239139&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Fri Jun  5 04:31:20 2015
@@ -292,28 +292,10 @@ static Value *SimplifyWithOpReplaced(Val
 
   // If this is a binary operator, try to simplify it with the replaced op.
   if (BinaryOperator *B = dyn_cast<BinaryOperator>(I)) {
-    Value *Simplified = nullptr;
     if (B->getOperand(0) == Op)
-      Simplified =
-          SimplifyBinOp(B->getOpcode(), RepOp, B->getOperand(1), DL, TLI);
-    if (!Simplified && B->getOperand(1) == Op)
-      Simplified =
-          SimplifyBinOp(B->getOpcode(), B->getOperand(0), RepOp, DL, TLI);
-    if (Simplified) {
-      // Consider:
-      //   %cmp = icmp eq i32 %x, 2147483647
-      //   %add = add nsw i32 %x, 1
-      //   %sel = select i1 %cmp, i32 -2147483648, i32 %add
-      //
-      // We can't replace %sel with %add unless we strip away the flags.
-      if (isa<OverflowingBinaryOperator>(B)) {
-        B->setHasNoSignedWrap(false);
-        B->setHasNoUnsignedWrap(false);
-      }
-      if (isa<PossiblyExactOperator>(B))
-        B->setIsExact(false);
-    }
-    return Simplified;
+      return SimplifyBinOp(B->getOpcode(), RepOp, B->getOperand(1), DL, TLI);
+    if (B->getOperand(1) == Op)
+      return SimplifyBinOp(B->getOpcode(), B->getOperand(0), RepOp, DL, TLI);
   }
 
   // Same for CmpInsts.

Modified: llvm/trunk/test/Transforms/InstCombine/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select.ll?rev=239139&r1=239138&r2=239139&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/select.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/select.ll Fri Jun  5 04:31:20 2015
@@ -1532,13 +1532,3 @@ define i32 @test_max_of_min(i32 %a) {
   %s1 = select i1 %c1, i32 %s0, i32 -1
   ret i32 %s1
 }
-
-define i32 @PR23757(i32 %x) {
-; CHECK-LABEL: @PR23757
-; CHECK:      %[[add:.*]] = add i32 %x, 1
-; CHECK-NEXT: ret i32 %[[add]]
-  %cmp = icmp eq i32 %x, 2147483647
-  %add = add nsw i32 %x, 1
-  %sel = select i1 %cmp, i32 -2147483648, i32 %add
-  ret i32 %sel
-}





More information about the llvm-commits mailing list