[llvm] d6dd938 - [IndVars] IV user should not prevent use widening
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 11 21:02:35 PST 2020
Author: Max Kazantsev
Date: 2020-11-12T12:02:01+07:00
New Revision: d6dd9385893e034c7c3561e5d47dc5cf3bce4552
URL: https://github.com/llvm/llvm-project/commit/d6dd9385893e034c7c3561e5d47dc5cf3bce4552
DIFF: https://github.com/llvm/llvm-project/commit/d6dd9385893e034c7c3561e5d47dc5cf3bce4552.diff
LOG: [IndVars] IV user should not prevent use widening
Sometimes the an instruction we are trying to widen is used by the IV
(which means the instruction is the IV increment). Currently this may
prevent its widening. We should ignore such user because it will be
dead once the transform is done anyways.
Differential Revision: https://reviews.llvm.org/D90920
Reviewed By: fhahn
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index c7c081522f72..8e2fa03e760c 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -1566,7 +1566,11 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) {
if (!AddRecOp1 || AddRecOp1->getLoop() != L)
return false;
+ // Check that all uses are either s/zext, or narrow def (in case of we are
+ // widening the IV increment).
for (Use &U : NarrowUse->uses()) {
+ if (U.getUser() == NarrowDef)
+ continue;
Instruction *User = nullptr;
if (ExtKind == SignExtended)
User = dyn_cast<SExtInst>(U.getUser());
@@ -1597,6 +1601,9 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) {
ExtendKindMap[NarrowUse] = ExtKind;
for (Use &U : NarrowUse->uses()) {
+ // Ignore narrow def: it will be removed after the transform.
+ if (U.getUser() == NarrowDef)
+ continue;
Instruction *User = nullptr;
if (ExtKind == SignExtended)
User = cast<SExtInst>(U.getUser());
diff --git a/llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll b/llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll
index 48195a299fc8..8d1303d382de 100644
--- a/llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll
+++ b/llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll
@@ -607,13 +607,10 @@ define i32 @test12(i32 %start, i32* %p, i32* %q) {
; CHECK-NEXT: [[COND:%.*]] = icmp eq i64 [[INDVARS_IV]], 0
; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[BACKEDGE]]
; CHECK: backedge:
-; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[INDVARS_IV]] to i32
-; CHECK-NEXT: [[IV_NEXT:%.*]] = add i32 [[TMP1]], -1
-; CHECK-NEXT: [[INDEX:%.*]] = zext i32 [[IV_NEXT]] to i64
-; CHECK-NEXT: [[STORE_ADDR:%.*]] = getelementptr i32, i32* [[P:%.*]], i64 [[INDEX]]
+; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[INDVARS_IV]], -1
+; CHECK-NEXT: [[STORE_ADDR:%.*]] = getelementptr i32, i32* [[P:%.*]], i64 [[TMP1]]
; CHECK-NEXT: store i32 1, i32* [[STORE_ADDR]], align 4
-; CHECK-NEXT: [[LOAD_ADDR:%.*]] = getelementptr i32, i32* [[Q:%.*]], i64 [[INDEX]]
-; CHECK-NEXT: [[STOP:%.*]] = load i32, i32* [[Q]], align 4
+; CHECK-NEXT: [[STOP:%.*]] = load i32, i32* [[Q:%.*]], align 4
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp eq i32 [[STOP]], 0
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nsw i64 [[INDVARS_IV]], -1
; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[FAILURE:%.*]]
More information about the llvm-commits
mailing list