[PATCH] D109054: [SImplifyCFG] Preserve knowledge about guarding condition by adding assume

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 8 00:06:21 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG29d054bf1268: [SimplifyCFG] Preserve knowledge about guarding condition by adding assume (authored by mkazantsev).

Changed prior to commit:
  https://reviews.llvm.org/D109054?vs=370842&id=371261#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109054/new/

https://reviews.llvm.org/D109054

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch.ll


Index: llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch.ll
+++ llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch.ll
@@ -14,8 +14,12 @@
 ; CHECK-NEXT:    unreachable
 ; CHECK:       bb21:
 ; CHECK-NEXT:    [[I:%.*]] = icmp eq %0* [[ARG17:%.*]], null
+; CHECK-NEXT:    [[TMP0:%.*]] = xor i1 [[I]], true
+; CHECK-NEXT:    call void @llvm.assume(i1 [[TMP0]])
 ; CHECK-NEXT:    call void @hoge()
-; CHECK-NEXT:    [[I27:%.*]] = getelementptr inbounds [[TMP0:%.*]], %0* [[ARG19:%.*]], i64 0, i32 0
+; CHECK-NEXT:    [[TMP1:%.*]] = xor i1 [[ARG16:%.*]], true
+; CHECK-NEXT:    call void @llvm.assume(i1 [[TMP1]])
+; CHECK-NEXT:    [[I27:%.*]] = getelementptr inbounds [[TMP0]], %0* [[ARG19:%.*]], i64 0, i32 0
 ; CHECK-NEXT:    [[I28:%.*]] = load %1*, %1** [[I27]], align 8
 ; CHECK-NEXT:    call void @pluto.1(%1* [[I28]])
 ; CHECK-NEXT:    call void @pluto()
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6598,9 +6598,17 @@
           // destination from conditional branches.
           if (BI->isUnconditional())
             Builder.CreateUnreachable();
-          else
+          else {
+            // Preserve guarding condition in assume, because it might not be
+            // inferrable from any dominating condition.
+            Value *Cond = BI->getCondition();
+            if (BI->getSuccessor(0) == BB)
+              Builder.CreateAssumption(Builder.CreateNot(Cond));
+            else
+              Builder.CreateAssumption(Cond);
             Builder.CreateBr(BI->getSuccessor(0) == BB ? BI->getSuccessor(1)
                                                        : BI->getSuccessor(0));
+          }
           BI->eraseFromParent();
           if (DTU)
             DTU->applyUpdates({{DominatorTree::Delete, Predecessor, BB}});


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109054.371261.patch
Type: text/x-patch
Size: 2084 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210908/60fbf8f9/attachment.bin>


More information about the llvm-commits mailing list