[llvm] 079c525 - [SCEV] Try simplifying phi before createNodeFromSelectLikePHI()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 27 06:07:30 PDT 2023
Author: Nikita Popov
Date: 2023-04-27T15:07:19+02:00
New Revision: 079c525f206228c3343048bb5a74a8e9a428de1a
URL: https://github.com/llvm/llvm-project/commit/079c525f206228c3343048bb5a74a8e9a428de1a
DIFF: https://github.com/llvm/llvm-project/commit/079c525f206228c3343048bb5a74a8e9a428de1a.diff
LOG: [SCEV] Try simplifying phi before createNodeFromSelectLikePHI()
Sometimes a phi can both be trivial and match the
createNodeFromSelectLikePHI() fold. In that case it is generally
more profitable to look through the phi node.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/trivial-phis.ll
llvm/test/Transforms/IndVarSimplify/lftr-pr20680.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 6bfb5c0567034..d7aeb0b286090 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6050,12 +6050,12 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) {
if (const SCEV *S = createAddRecFromPHI(PN))
return S;
- if (const SCEV *S = createNodeFromSelectLikePHI(PN))
- return S;
-
if (Value *V = simplifyInstruction(PN, {getDataLayout(), &TLI, &DT, &AC}))
return getSCEV(V);
+ if (const SCEV *S = createNodeFromSelectLikePHI(PN))
+ return S;
+
// If it's not a loop phi, we can't handle it yet.
return getUnknown(PN);
}
diff --git a/llvm/test/Analysis/ScalarEvolution/trivial-phis.ll b/llvm/test/Analysis/ScalarEvolution/trivial-phis.ll
index ecd5d46e84f01..7916c509a33bc 100644
--- a/llvm/test/Analysis/ScalarEvolution/trivial-phis.ll
+++ b/llvm/test/Analysis/ScalarEvolution/trivial-phis.ll
@@ -24,7 +24,7 @@ do.end: ; preds = %do.body
; CHECK-LABEL: @test2
; CHECK: %tmp24 = phi i64 [ %tmp14, %bb22 ], [ %tmp14, %bb13 ]
-; CHECK-NEXT: --> %tmp24 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb13: Variant, %bb8: Variant, %bb17: Invariant, %bb27: Invariant }
+; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%bb13> U: [1,9223372036854775807) S: [1,9223372036854775807) Exits: (-2 + %arg)
define void @test2(i64 %arg, ptr noalias %arg1) {
bb:
diff --git a/llvm/test/Transforms/IndVarSimplify/lftr-pr20680.ll b/llvm/test/Transforms/IndVarSimplify/lftr-pr20680.ll
index 02de829421f4c..3e24bcd98e42d 100644
--- a/llvm/test/Transforms/IndVarSimplify/lftr-pr20680.ll
+++ b/llvm/test/Transforms/IndVarSimplify/lftr-pr20680.ll
@@ -21,9 +21,6 @@ define void @f() {
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_INC13:%.*]] ], [ -14, [[ENTRY:%.*]] ]
; CHECK-NEXT: br i1 [[TOBOOL2]], label [[FOR_INC13]], label [[FOR_BODY3_LR_PH:%.*]]
; CHECK: for.body3.lr.ph:
-; CHECK-NEXT: [[TMP2:%.*]] = add nsw i32 [[INDVARS_IV]], 1
-; CHECK-NEXT: [[TMP3:%.*]] = icmp ult i32 [[TMP2]], 3
-; CHECK-NEXT: [[DIV:%.*]] = select i1 [[TMP3]], i32 [[INDVARS_IV]], i32 0
; CHECK-NEXT: br i1 false, label [[FOR_BODY3_LR_PH_SPLIT_US:%.*]], label [[FOR_BODY3_LR_PH_FOR_BODY3_LR_PH_SPLIT_CRIT_EDGE:%.*]]
; CHECK: for.body3.lr.ph.for.body3.lr.ph.split_crit_edge:
; CHECK-NEXT: br label [[FOR_BODY3_LR_PH_SPLIT:%.*]]
@@ -38,8 +35,8 @@ define void @f() {
; CHECK: cond.false.us.us:
; CHECK-NEXT: br label [[COND_END_US_US]]
; CHECK: cond.end.us.us:
-; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr @b, align 4
-; CHECK-NEXT: [[CMP91_US_US:%.*]] = icmp slt i32 [[TMP4]], 1
+; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr @b, align 4
+; CHECK-NEXT: [[CMP91_US_US:%.*]] = icmp slt i32 [[TMP2]], 1
; CHECK-NEXT: br i1 [[CMP91_US_US]], label [[FOR_INC_LR_PH_US_US:%.*]], label [[FOR_COND2_LOOPEXIT_US_US:%.*]]
; CHECK: for.cond2.loopexit.us.us:
; CHECK-NEXT: br i1 true, label [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US_US_LCSSA_US:%.*]], label [[FOR_BODY3_US_US]]
@@ -49,8 +46,8 @@ define void @f() {
; CHECK-NEXT: store i32 1, ptr @b, align 4
; CHECK-NEXT: br label [[FOR_COND2_LOOPEXIT_US_US]]
; CHECK: for.inc.us.us:
-; CHECK-NEXT: [[TMP5:%.*]] = phi i32 [ [[TMP4]], [[FOR_INC_LR_PH_US_US]] ], [ [[INC_US_US:%.*]], [[FOR_INC_US_US]] ]
-; CHECK-NEXT: [[INC_US_US]] = add nsw i32 [[TMP5]], 1
+; CHECK-NEXT: [[TMP3:%.*]] = phi i32 [ [[TMP2]], [[FOR_INC_LR_PH_US_US]] ], [ [[INC_US_US:%.*]], [[FOR_INC_US_US]] ]
+; CHECK-NEXT: [[INC_US_US]] = add nsw i32 [[TMP3]], 1
; CHECK-NEXT: [[EXITCOND3:%.*]] = icmp ne i32 [[INC_US_US]], 1
; CHECK-NEXT: br i1 [[EXITCOND3]], label [[FOR_INC_US_US]], label [[FOR_COND8_FOR_COND2_LOOPEXIT_CRIT_EDGE_US_US:%.*]]
; CHECK: for.cond2.for.inc13_crit_edge.us-lcssa.us.us-lcssa.us:
@@ -62,12 +59,12 @@ define void @f() {
; CHECK: cond.false.us:
; CHECK-NEXT: br label [[COND_END_US]]
; CHECK: cond.end.us:
-; CHECK-NEXT: [[TMP6:%.*]] = load i32, ptr @b, align 4
-; CHECK-NEXT: [[CMP91_US:%.*]] = icmp slt i32 [[TMP6]], 1
+; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr @b, align 4
+; CHECK-NEXT: [[CMP91_US:%.*]] = icmp slt i32 [[TMP4]], 1
; CHECK-NEXT: br i1 [[CMP91_US]], label [[FOR_INC_LR_PH_US:%.*]], label [[FOR_COND2_LOOPEXIT_US:%.*]]
; CHECK: for.inc.us:
-; CHECK-NEXT: [[TMP7:%.*]] = phi i32 [ [[TMP6]], [[FOR_INC_LR_PH_US]] ], [ [[INC_US:%.*]], [[FOR_INC_US:%.*]] ]
-; CHECK-NEXT: [[INC_US]] = add nsw i32 [[TMP7]], 1
+; CHECK-NEXT: [[TMP5:%.*]] = phi i32 [ [[TMP4]], [[FOR_INC_LR_PH_US]] ], [ [[INC_US:%.*]], [[FOR_INC_US:%.*]] ]
+; CHECK-NEXT: [[INC_US]] = add nsw i32 [[TMP5]], 1
; CHECK-NEXT: [[EXITCOND2:%.*]] = icmp ne i32 [[INC_US]], 1
; CHECK-NEXT: br i1 [[EXITCOND2]], label [[FOR_INC_US]], label [[FOR_COND8_FOR_COND2_LOOPEXIT_CRIT_EDGE_US:%.*]]
; CHECK: for.cond2.loopexit.us:
@@ -80,7 +77,6 @@ define void @f() {
; CHECK: for.cond2.for.inc13_crit_edge.us-lcssa.us.us-lcssa:
; CHECK-NEXT: br label [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US]]
; CHECK: for.cond2.for.inc13_crit_edge.us-lcssa.us:
-; CHECK-NEXT: [[COND_LCSSA_PH_US:%.*]] = phi i32 [ [[DIV]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US_US_LCSSA]] ], [ [[DIV]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US_US_LCSSA_US]] ]
; CHECK-NEXT: br label [[FOR_COND2_FOR_INC13_CRIT_EDGE:%.*]]
; CHECK: for.body3.lr.ph.split:
; CHECK-NEXT: br i1 [[TOBOOL]], label [[FOR_BODY3_LR_PH_SPLIT_SPLIT_US:%.*]], label [[FOR_BODY3_LR_PH_SPLIT_FOR_BODY3_LR_PH_SPLIT_SPLIT_CRIT_EDGE:%.*]]
@@ -93,12 +89,12 @@ define void @f() {
; CHECK: cond.false.us4:
; CHECK-NEXT: br label [[COND_END_US5]]
; CHECK: cond.end.us5:
-; CHECK-NEXT: [[TMP8:%.*]] = load i32, ptr @b, align 4
-; CHECK-NEXT: [[CMP91_US7:%.*]] = icmp slt i32 [[TMP8]], 1
+; CHECK-NEXT: [[TMP6:%.*]] = load i32, ptr @b, align 4
+; CHECK-NEXT: [[CMP91_US7:%.*]] = icmp slt i32 [[TMP6]], 1
; CHECK-NEXT: br i1 [[CMP91_US7]], label [[FOR_INC_LR_PH_US12:%.*]], label [[FOR_COND2_LOOPEXIT_US11:%.*]]
; CHECK: for.inc.us8:
-; CHECK-NEXT: [[TMP9:%.*]] = phi i32 [ [[TMP8]], [[FOR_INC_LR_PH_US12]] ], [ [[INC_US9:%.*]], [[FOR_INC_US8:%.*]] ]
-; CHECK-NEXT: [[INC_US9]] = add nsw i32 [[TMP9]], 1
+; CHECK-NEXT: [[TMP7:%.*]] = phi i32 [ [[TMP6]], [[FOR_INC_LR_PH_US12]] ], [ [[INC_US9:%.*]], [[FOR_INC_US8:%.*]] ]
+; CHECK-NEXT: [[INC_US9]] = add nsw i32 [[TMP7]], 1
; CHECK-NEXT: [[EXITCOND1:%.*]] = icmp ne i32 [[INC_US9]], 1
; CHECK-NEXT: br i1 [[EXITCOND1]], label [[FOR_INC_US8]], label [[FOR_COND8_FOR_COND2_LOOPEXIT_CRIT_EDGE_US13:%.*]]
; CHECK: for.cond2.loopexit.us11:
@@ -122,24 +118,22 @@ define void @f() {
; CHECK: cond.false:
; CHECK-NEXT: br label [[COND_END]]
; CHECK: cond.end:
-; CHECK-NEXT: [[TMP10:%.*]] = load i32, ptr @b, align 4
-; CHECK-NEXT: [[CMP91:%.*]] = icmp slt i32 [[TMP10]], 1
+; CHECK-NEXT: [[TMP8:%.*]] = load i32, ptr @b, align 4
+; CHECK-NEXT: [[CMP91:%.*]] = icmp slt i32 [[TMP8]], 1
; CHECK-NEXT: br i1 [[CMP91]], label [[FOR_INC_LR_PH:%.*]], label [[FOR_COND2_LOOPEXIT]]
; CHECK: for.inc.lr.ph:
; CHECK-NEXT: br label [[FOR_INC:%.*]]
; CHECK: for.inc:
-; CHECK-NEXT: [[TMP11:%.*]] = phi i32 [ [[TMP10]], [[FOR_INC_LR_PH]] ], [ [[INC:%.*]], [[FOR_INC]] ]
-; CHECK-NEXT: [[INC]] = add nsw i32 [[TMP11]], 1
+; CHECK-NEXT: [[TMP9:%.*]] = phi i32 [ [[TMP8]], [[FOR_INC_LR_PH]] ], [ [[INC:%.*]], [[FOR_INC]] ]
+; CHECK-NEXT: [[INC]] = add nsw i32 [[TMP9]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INC]], 1
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_INC]], label [[FOR_COND8_FOR_COND2_LOOPEXIT_CRIT_EDGE:%.*]]
; CHECK: for.cond2.for.inc13_crit_edge.us-lcssa.us-lcssa:
; CHECK-NEXT: br label [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA]]
; CHECK: for.cond2.for.inc13_crit_edge.us-lcssa:
-; CHECK-NEXT: [[COND_LCSSA_PH:%.*]] = phi i32 [ [[INDVARS_IV]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US_LCSSA]] ], [ [[INDVARS_IV]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US_LCSSA_US]] ]
; CHECK-NEXT: br label [[FOR_COND2_FOR_INC13_CRIT_EDGE]]
; CHECK: for.cond2.for.inc13_crit_edge:
-; CHECK-NEXT: [[COND_LCSSA:%.*]] = phi i32 [ [[COND_LCSSA_PH]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA]] ], [ [[COND_LCSSA_PH_US]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US]] ]
-; CHECK-NEXT: store i32 [[COND_LCSSA]], ptr @c, align 4
+; CHECK-NEXT: store i32 [[INDVARS_IV]], ptr @c, align 4
; CHECK-NEXT: br label [[FOR_INC13]]
; CHECK: for.inc13:
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nsw i32 [[INDVARS_IV]], 1
More information about the llvm-commits
mailing list