[llvm] r333864 - [InstCombine] Fix div handling

Serguei Katkov via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 3 19:52:36 PDT 2018


Author: skatkov
Date: Sun Jun  3 19:52:36 2018
New Revision: 333864

URL: http://llvm.org/viewvc/llvm-project?rev=333864&view=rev
Log:
[InstCombine] Fix div handling

When we optimize select basing on fact that div by 0 is undef
we should not traverse the instruction which are not guaranteed to
transfer execution to next instruction. Guard intrinsic is an example.

Reviewers: spatel, craig.topper
Reviewed By: spatel
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D47576

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    llvm/trunk/test/Transforms/InstCombine/sdiv-guard.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=333864&r1=333863&r2=333864&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Sun Jun  3 19:52:36 2018
@@ -581,9 +581,9 @@ bool InstCombiner::simplifyDivRemOfSelec
   Type *CondTy = SelectCond->getType();
   while (BBI != BBFront) {
     --BBI;
-    // If we found a call to a function, we can't assume it will return, so
+    // If we found an instruction that we can't assume will return, so
     // information from below it cannot be propagated above it.
-    if (isa<CallInst>(BBI) && !isa<IntrinsicInst>(BBI))
+    if (!isGuaranteedToTransferExecutionToSuccessor(&*BBI))
       break;
 
     // Replace uses of the select or its condition with the known values.

Modified: llvm/trunk/test/Transforms/InstCombine/sdiv-guard.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sdiv-guard.ll?rev=333864&r1=333863&r2=333864&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sdiv-guard.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sdiv-guard.ll Sun Jun  3 19:52:36 2018
@@ -3,11 +3,11 @@
 
 declare void @llvm.experimental.guard(i1, ...)
 
-; FIXME: If %flag is false then %s == 0 and guard should be triggered.
-
+; Regression test. If %flag is false then %s == 0 and guard should be triggered.
 define i32 @a(i1 %flag, i32 %X) nounwind readnone {
 ; CHECK-LABEL: @a(
-; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[CMP:%.*]] = and i1 [[CMP1]], [[FLAG:%.*]]
 ; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[CMP]]) #1 [ "deopt"() ]
 ; CHECK-NEXT:    [[R:%.*]] = sdiv i32 100, [[X]]
 ; CHECK-NEXT:    ret i32 [[R]]
@@ -18,4 +18,3 @@ define i32 @a(i1 %flag, i32 %X) nounwind
   %r = sdiv i32 100, %s
   ret i32 %r
 }
-




More information about the llvm-commits mailing list