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

Dmitry Bakunevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 3 03:55:01 PDT 2021


dbakunevich updated this revision to Diff 370533.

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
+          // These changes have been added to preserve knowledge of the 
+          // protection state by adding a guess.
+          else {
+            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.370533.patch
Type: text/x-patch
Size: 2071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210903/06f2bf2d/attachment.bin>


More information about the llvm-commits mailing list