llvm.org GIT mirror llvm / 5b64093
[IndVars] Ignore (s|z)exts that don't extend the induction variable `IVVisitor::visitCast` used to have the invariant that if the instruction it was passed was a sext or zext instruction, the result of the instruction would be wider than the induction variable. This is no longer true after rL275037, so this change teaches `IndVarSimplify` s implementation of `IVVisitor::visitCast` to work with the relaxed invariant. A corresponding change to SimplifyIndVar to preserve the said invariant after rL275037 would also work, but given how `IVVisitor::visitCast` is spelled (no indication of said invariant), I figured the current fix is cleaner. Fixes PR28935. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278584 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 3 years ago
2 changed file(s) with 28 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
815815 if (!Cast->getModule()->getDataLayout().isLegalInteger(Width))
816816 return;
818 // Check that `Cast` actually extends the induction variable (we rely on this
819 // later). This takes care of cases where `Cast` is extending a truncation of
820 // the narrow induction variable, and thus can end up being narrower than the
821 // "narrow" induction variable.
822 uint64_t NarrowIVWidth = SE->getTypeSizeInBits(WI.NarrowIV->getType());
823 if (NarrowIVWidth >= Width)
824 return;
818826 // Cast is either an sext or zext up to this point.
819827 // We should not widen an indvar if arithmetics on the wider indvar are more
820828 // expensive than those on the narrower indvar. We check only the cost of ADD
0 ; RUN: opt -S -indvars < %s | FileCheck %s
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
5 declare i16 @fn1(i16 returned, i64)
7 define void @fn2() {
8 ; CHECK-LABEL: @fn2(
9 entry:
10 br label %for.cond
12 for.cond:
13 %f.0 = phi i64 [ undef, %entry ], [ %inc, %for.cond ]
14 %conv = trunc i64 %f.0 to i16
15 %call = tail call i16 @fn1(i16 %conv, i64 %f.0)
16 %conv2 = zext i16 %call to i32
17 %inc = add nsw i64 %f.0, 1
18 br label %for.cond
19 }