llvm.org GIT mirror llvm / d8d6388
Revert -r278269 [IndVarSimplify] Eliminate zext of a signed IV when the IV is known to be non-negative This change needs to be reverted in order to revert -r278267 which cause performance regression on MultiSource/Benchmarks/TSVC/Symbolics-flt/Symbolics-flt from LNT and some other bechmarks. See comments on https://reviews.llvm.org/D18777 for details. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279432 91177308-0d34-0410-b5e6-96231b3b80d8 Artur Pilipenko 3 years ago
2 changed file(s) with 2 addition(s) and 89 deletion(s). Raw diff Collapse all Expand all
3535 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
3636 #include "llvm/Analysis/TargetLibraryInfo.h"
3737 #include "llvm/Analysis/TargetTransformInfo.h"
38 #include "llvm/Analysis/ValueTracking.h"
3938 #include "llvm/IR/BasicBlock.h"
4039 #include "llvm/IR/CFG.h"
4140 #include "llvm/IR/Constants.h"
12891288 }
12901289 }
12911290 // Our raison d'etre! Eliminate sign and zero extension.
1292 if ((isa(DU.NarrowUse) && (IsSigned || DU.NeverNegative)) ||
1293 (isa(DU.NarrowUse) && (!IsSigned || DU.NeverNegative))) {
1291 if (IsSigned ? isa(DU.NarrowUse) : isa(DU.NarrowUse)) {
12941292 Value *NewDef = DU.WideDef;
12951293 if (DU.NarrowUse->getType() != WideType) {
12961294 unsigned CastWidth = SE->getTypeSizeInBits(DU.NarrowUse->getType());
13791377 ///
13801378 void WidenIV::pushNarrowIVUsers(Instruction *NarrowDef, Instruction *WideDef) {
13811379 const SCEV *NarrowSCEV = SE->getSCEV(NarrowDef);
1382 // isKnownPredicate is enough for most cases but still need isKnownNonNegative
1383 // here to work around conservatism in ScalarEvolution about no-wrap flags.
13841380 bool NeverNegative =
13851381 SE->isKnownPredicate(ICmpInst::ICMP_SGE, NarrowSCEV,
1386 SE->getConstant(NarrowSCEV->getType(), 0)) ||
1387 isKnownNonNegative(NarrowDef, NarrowDef->getModule()->getDataLayout());
1382 SE->getConstant(NarrowSCEV->getType(), 0));
13881383 for (User *U : NarrowDef->users()) {
13891384 Instruction *NarrowUser = cast(U);
13901385
+0
-82
test/Transforms/IndVarSimplify/iv-widen-elim-ext.ll less more
None ; RUN: opt < %s -indvars -S | FileCheck %s --implicit-check-not sext --implicit-check-not zext
1
2 target datalayout = "p:64:64:64-n32:64"
3
4 ; When widening IV and its users, trunc and zext/sext are not needed
5 ; if the original 32-bit user is known to be non-negative, whether
6 ; the IV is considered signed or unsigned.
7 define void @foo(i32* %A, i32* %B, i32* %C, i32 %N) {
8 ; CHECK-LABEL: @foo(
9 ; CHECK: wide.trip.count = zext
10 ; CHECK: ret void
11 entry:
12 %cmp1 = icmp slt i32 0, %N
13 br i1 %cmp1, label %for.body.lr.ph, label %for.end
14
15 for.body.lr.ph: ; preds = %entry
16 br label %for.body
17
18 for.body: ; preds = %for.body.lr.ph, %for.inc
19 %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
20 %idxprom = sext i32 %i.02 to i64
21 %arrayidx = getelementptr inbounds i32, i32* %B, i64 %idxprom
22 %0 = load i32, i32* %arrayidx, align 4
23 %add = add nsw i32 %i.02, 2
24 %idxprom1 = zext i32 %add to i64
25 %arrayidx2 = getelementptr inbounds i32, i32* %C, i64 %idxprom1
26 %1 = load i32, i32* %arrayidx2, align 4
27 %add3 = add nsw i32 %0, %1
28 %idxprom4 = zext i32 %i.02 to i64
29 %arrayidx5 = getelementptr inbounds i32, i32* %A, i64 %idxprom4
30 store i32 %add3, i32* %arrayidx5, align 4
31 br label %for.inc
32
33 for.inc: ; preds = %for.body
34 %inc = add nsw i32 %i.02, 1
35 %cmp = icmp slt i32 %inc, %N
36 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
37
38 for.cond.for.end_crit_edge: ; preds = %for.inc
39 br label %for.end
40
41 for.end: ; preds = %for.cond.for.end_crit_edge, %entry
42 ret void
43 }
44
45 define void @foo1(i32* %A, i32* %B, i32* %C, i32 %N) {
46 ; CHECK-LABEL: @foo1(
47 ; CHECK: wide.trip.count = zext
48 ; CHECK: ret void
49 entry:
50 %cmp1 = icmp slt i32 0, %N
51 br i1 %cmp1, label %for.body.lr.ph, label %for.end
52
53 for.body.lr.ph: ; preds = %entry
54 br label %for.body
55
56 for.body: ; preds = %for.body.lr.ph, %for.inc
57 %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
58 %idxprom = zext i32 %i.02 to i64
59 %arrayidx = getelementptr inbounds i32, i32* %B, i64 %idxprom
60 %0 = load i32, i32* %arrayidx, align 4
61 %add = add nsw i32 %i.02, 2
62 %idxprom1 = sext i32 %add to i64
63 %arrayidx2 = getelementptr inbounds i32, i32* %C, i64 %idxprom1
64 %1 = load i32, i32* %arrayidx2, align 4
65 %add3 = add nsw i32 %0, %1
66 %idxprom4 = sext i32 %i.02 to i64
67 %arrayidx5 = getelementptr inbounds i32, i32* %A, i64 %idxprom4
68 store i32 %add3, i32* %arrayidx5, align 4
69 br label %for.inc
70
71 for.inc: ; preds = %for.body
72 %inc = add nsw i32 %i.02, 1
73 %cmp = icmp slt i32 %inc, %N
74 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
75
76 for.cond.for.end_crit_edge: ; preds = %for.inc
77 br label %for.end
78
79 for.end: ; preds = %for.cond.for.end_crit_edge, %entry
80 ret void
81 }