[PATCH] D135369: [DSE] Relax constraint on isGuaranteedLoopInvariant

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 8 23:59:59 PDT 2022


StephenFan updated this revision to Diff 466351.
StephenFan added a comment.

1. Add a testcase
2. Check isEntryBlock no matter if contains irreducible loops


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135369

Files:
  llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
  llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll
  llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll


Index: llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll
+++ llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll
@@ -170,7 +170,6 @@
 ; CHECK-NEXT:    br i1 true, label [[BB2:%.*]], label [[BB3:%.*]]
 ; CHECK:       bb2:
 ; CHECK-NEXT:    [[M:%.*]] = call noalias ptr @malloc(i64 10)
-; CHECK-NEXT:    store i8 1, ptr [[M]], align 1
 ; CHECK-NEXT:    br label [[BB3]]
 ; CHECK:       bb3:
 ; CHECK-NEXT:    [[R:%.*]] = phi ptr [ null, [[BB1:%.*]] ], [ [[M]], [[BB2]] ]
Index: llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll
+++ llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll
@@ -617,6 +617,32 @@
   ret i16 0
 }
 
+define i16 @irreducible_entryblock_def(i1 %c) {
+; CHECK-LABEL: @irreducible_entryblock_def(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br i1 [[C:%.*]], label [[A:%.*]], label [[B:%.*]]
+; CHECK:       A:
+; CHECK-NEXT:    br label [[B]]
+; CHECK:       B:
+; CHECK-NEXT:    br i1 [[C]], label [[EXIT:%.*]], label [[A]]
+; CHECK:       exit:
+; CHECK-NEXT:    ret i16 0
+;
+entry:
+  %obj = alloca i32, align 4
+  br i1 %c, label %A, label %B
+
+A:
+  store i32 1, ptr %obj, align 4
+  br label %B
+
+B:
+  br i1 %c, label %exit, label %A
+
+exit:
+  ret i16 0
+}
+
 ; An irreducible loop inside another loop.
 define i16 @irreducible_nested() {
 ; CHECK-LABEL: @irreducible_nested(
@@ -846,7 +872,6 @@
 ; CHECK-NEXT:    br label [[FIRST:%.*]]
 ; CHECK:       first:
 ; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [10 x i16], ptr @x, i16 0, i32 [[I:%.*]]
-; CHECK-NEXT:    store i16 1, ptr [[ARRAYIDX]], align 1
 ; CHECK-NEXT:    br label [[DO_BODY:%.*]]
 ; CHECK:       do.body:
 ; CHECK-NEXT:    [[I_0:%.*]] = phi i16 [ 0, [[FIRST]] ], [ [[INC:%.*]], [[DO_BODY]] ]
Index: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1215,8 +1215,10 @@
       if (GEP->hasAllConstantIndices())
         Ptr = GEP->getPointerOperand()->stripPointerCasts();
 
-    if (auto *I = dyn_cast<Instruction>(Ptr))
-      return I->getParent()->isEntryBlock();
+    if (auto *I = dyn_cast<Instruction>(Ptr)) {
+      return I->getParent()->isEntryBlock() ||
+             (!ContainsIrreducibleLoops && !LI.getLoopFor(I->getParent()));
+    }
     return true;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135369.466351.patch
Type: text/x-patch
Size: 2696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221009/1d8cfe13/attachment.bin>


More information about the llvm-commits mailing list