[llvm] eaf6e2f - [DSE] Relax constraint on isGuaranteedLoopInvariant
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 9 09:10:42 PDT 2022
Author: luxufan
Date: 2022-10-06T03:01:21Z
New Revision: eaf6e2fc337ce428ae87d57360a2168c415acb5d
URL: https://github.com/llvm/llvm-project/commit/eaf6e2fc337ce428ae87d57360a2168c415acb5d
DIFF: https://github.com/llvm/llvm-project/commit/eaf6e2fc337ce428ae87d57360a2168c415acb5d.diff
LOG: [DSE] Relax constraint on isGuaranteedLoopInvariant
If the location ptr to be killed is in no loop and the Function does not
have irreducible loops, then we can regard it as loop invariant.
Differential Revision: https://reviews.llvm.org/D135369
Added:
Modified:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll
llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 93abda04bd8f0..194220cd161d2 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1215,8 +1215,10 @@ struct DSEState {
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;
}
diff --git a/llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll b/llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll
index 142b14ff4ff38..dbeea99bbea57 100644
--- a/llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll
@@ -617,6 +617,32 @@ exit:
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 @@ define i16 @partial_override_overloop(i1 %c, i32 %i) {
; 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]] ]
diff --git a/llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll b/llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll
index e7f83bae04f77..e623aac919527 100644
--- a/llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll
@@ -170,7 +170,6 @@ define void @test27() {
; 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]] ]
More information about the llvm-commits
mailing list