[PATCH] D137060: [IndVars] Forget the SCEV when the instruction has been sunk.
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 3 08:36:42 PDT 2022
StephenFan updated this revision to Diff 472951.
StephenFan added a comment.
reduce test case.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137060/new/
https://reviews.llvm.org/D137060
Files:
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/test/Transforms/IndVarSimplify/pr58662.ll
Index: llvm/test/Transforms/IndVarSimplify/pr58662.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/IndVarSimplify/pr58662.ll
@@ -0,0 +1,58 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -indvars -S < %s | FileCheck %s
+
+; Check that the scalar evolution expression is forgot after the instruction being sunk.
+
+define i8 @l(i32 %inc, i1 %tobool.not.i) {
+; CHECK-LABEL: @l(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[FOR_COND:%.*]]
+; CHECK: for.cond:
+; CHECK-NEXT: br label [[WHILE_BODY_I:%.*]]
+; CHECK: while.body.i:
+; CHECK-NEXT: [[C_05_I:%.*]] = phi i32 [ [[INC_I:%.*]], [[WHILE_BODY_I]] ], [ 0, [[FOR_COND]] ]
+; CHECK-NEXT: [[INC_I]] = add nuw nsw i32 [[C_05_I]], 1
+; CHECK-NEXT: [[CMP_I:%.*]] = icmp ugt i32 [[C_05_I]], 0
+; CHECK-NEXT: [[OR_COND_I:%.*]] = select i1 [[CMP_I]], i1 true, i1 [[TOBOOL_NOT_I:%.*]]
+; CHECK-NEXT: br i1 [[OR_COND_I]], label [[H_EXIT:%.*]], label [[WHILE_BODY_I]]
+; CHECK: h.exit:
+; CHECK-NEXT: [[C_05_I_LCSSA:%.*]] = phi i32 [ [[C_05_I]], [[WHILE_BODY_I]] ]
+; CHECK-NEXT: [[INC_I_LCSSA:%.*]] = phi i32 [ 0, [[WHILE_BODY_I]] ]
+; CHECK-NEXT: [[AND:%.*]] = and i32 1, [[INC:%.*]]
+; CHECK-NEXT: [[TMP0:%.*]] = trunc i32 [[AND]] to i8
+; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[C_05_I_LCSSA]] to i8
+; CHECK-NEXT: [[TMP2:%.*]] = sub i8 [[TMP0]], [[TMP1]]
+; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i8 [[TMP2]], 0
+; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[FOR_COND]], label [[IF_THEN:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: ret i8 0
+;
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %h.exit, %entry
+ %storemerge = phi i16 [ 0, %entry ], [ %sub6, %h.exit ]
+ %and = and i32 1, %inc
+ %conv = sext i16 %storemerge to i32
+ br label %while.body.i
+
+while.body.i: ; preds = %while.body.i, %for.cond
+ %c.05.i = phi i32 [ %inc.i, %while.body.i ], [ 0, %for.cond ]
+ %i.addr.04.i = phi i32 [ 0, %while.body.i ], [ %conv, %for.cond ]
+ %inc.i = add nsw i32 %c.05.i, 1
+ %cmp.i = icmp sgt i32 %c.05.i, 0
+ %or.cond.i = select i1 %cmp.i, i1 true, i1 %tobool.not.i
+ br i1 %or.cond.i, label %h.exit, label %while.body.i
+
+h.exit: ; preds = %while.body.i
+ %inc.i.lcssa = phi i32 [ 0, %while.body.i ]
+ %0 = trunc i32 %and to i8
+ %1 = trunc i32 %c.05.i to i8
+ %2 = sub i8 %0, %1
+ %tobool.not = icmp eq i8 %2, 0
+ %sub6 = add i16 %storemerge, 1
+ br i1 %tobool.not, label %for.cond, label %if.then
+
+if.then: ; preds = %h.exit
+ ret i8 0
+}
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1281,7 +1281,7 @@
MadeAnyChanges = true;
ToMove->moveBefore(*ExitBlock, InsertPt);
- SE->forgetBlockAndLoopDispositions(ToMove);
+ SE->forgetValue(ToMove);
if (Done) break;
InsertPt = ToMove->getIterator();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137060.472951.patch
Type: text/x-patch
Size: 3212 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221103/f4e6f994/attachment.bin>
More information about the llvm-commits
mailing list