From d8d6388a4487fe4c4e4d9369f50d70cc22f7ce25 Mon Sep 17 00:00:00 2001 From: Artur Pilipenko Date: Mon, 22 Aug 2016 13:12:07 +0000 Subject: [PATCH] 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 --- lib/Transforms/Scalar/IndVarSimplify.cpp | 9 +-- .../Transforms/IndVarSimplify/iv-widen-elim-ext.ll | 82 ---------------------- 2 files changed, 2 insertions(+), 89 deletions(-) delete mode 100644 test/Transforms/IndVarSimplify/iv-widen-elim-ext.ll diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index a11bef5d784..f522ca044cf 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -36,7 +36,6 @@ #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" -#include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" #include "llvm/IR/Constants.h" @@ -1290,8 +1289,7 @@ Instruction *WidenIV::widenIVUse(NarrowIVDefUse DU, SCEVExpander &Rewriter) { } } // Our raison d'etre! Eliminate sign and zero extension. - if ((isa(DU.NarrowUse) && (IsSigned || DU.NeverNegative)) || - (isa(DU.NarrowUse) && (!IsSigned || DU.NeverNegative))) { + if (IsSigned ? isa(DU.NarrowUse) : isa(DU.NarrowUse)) { Value *NewDef = DU.WideDef; if (DU.NarrowUse->getType() != WideType) { unsigned CastWidth = SE->getTypeSizeInBits(DU.NarrowUse->getType()); @@ -1380,12 +1378,9 @@ Instruction *WidenIV::widenIVUse(NarrowIVDefUse DU, SCEVExpander &Rewriter) { /// void WidenIV::pushNarrowIVUsers(Instruction *NarrowDef, Instruction *WideDef) { const SCEV *NarrowSCEV = SE->getSCEV(NarrowDef); - // isKnownPredicate is enough for most cases but still need isKnownNonNegative - // here to work around conservatism in ScalarEvolution about no-wrap flags. bool NeverNegative = SE->isKnownPredicate(ICmpInst::ICMP_SGE, NarrowSCEV, - SE->getConstant(NarrowSCEV->getType(), 0)) || - isKnownNonNegative(NarrowDef, NarrowDef->getModule()->getDataLayout()); + SE->getConstant(NarrowSCEV->getType(), 0)); for (User *U : NarrowDef->users()) { Instruction *NarrowUser = cast(U); diff --git a/test/Transforms/IndVarSimplify/iv-widen-elim-ext.ll b/test/Transforms/IndVarSimplify/iv-widen-elim-ext.ll deleted file mode 100644 index 763156d16c6..00000000000 --- a/test/Transforms/IndVarSimplify/iv-widen-elim-ext.ll +++ /dev/null @@ -1,82 +0,0 @@ -; RUN: opt < %s -indvars -S | FileCheck %s --implicit-check-not sext --implicit-check-not zext - -target datalayout = "p:64:64:64-n32:64" - -; When widening IV and its users, trunc and zext/sext are not needed -; if the original 32-bit user is known to be non-negative, whether -; the IV is considered signed or unsigned. -define void @foo(i32* %A, i32* %B, i32* %C, i32 %N) { -; CHECK-LABEL: @foo( -; CHECK: wide.trip.count = zext -; CHECK: ret void -entry: - %cmp1 = icmp slt i32 0, %N - br i1 %cmp1, label %for.body.lr.ph, label %for.end - -for.body.lr.ph: ; preds = %entry - br label %for.body - -for.body: ; preds = %for.body.lr.ph, %for.inc - %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ] - %idxprom = sext i32 %i.02 to i64 - %arrayidx = getelementptr inbounds i32, i32* %B, i64 %idxprom - %0 = load i32, i32* %arrayidx, align 4 - %add = add nsw i32 %i.02, 2 - %idxprom1 = zext i32 %add to i64 - %arrayidx2 = getelementptr inbounds i32, i32* %C, i64 %idxprom1 - %1 = load i32, i32* %arrayidx2, align 4 - %add3 = add nsw i32 %0, %1 - %idxprom4 = zext i32 %i.02 to i64 - %arrayidx5 = getelementptr inbounds i32, i32* %A, i64 %idxprom4 - store i32 %add3, i32* %arrayidx5, align 4 - br label %for.inc - -for.inc: ; preds = %for.body - %inc = add nsw i32 %i.02, 1 - %cmp = icmp slt i32 %inc, %N - br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge - -for.cond.for.end_crit_edge: ; preds = %for.inc - br label %for.end - -for.end: ; preds = %for.cond.for.end_crit_edge, %entry - ret void -} - -define void @foo1(i32* %A, i32* %B, i32* %C, i32 %N) { -; CHECK-LABEL: @foo1( -; CHECK: wide.trip.count = zext -; CHECK: ret void -entry: - %cmp1 = icmp slt i32 0, %N - br i1 %cmp1, label %for.body.lr.ph, label %for.end - -for.body.lr.ph: ; preds = %entry - br label %for.body - -for.body: ; preds = %for.body.lr.ph, %for.inc - %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ] - %idxprom = zext i32 %i.02 to i64 - %arrayidx = getelementptr inbounds i32, i32* %B, i64 %idxprom - %0 = load i32, i32* %arrayidx, align 4 - %add = add nsw i32 %i.02, 2 - %idxprom1 = sext i32 %add to i64 - %arrayidx2 = getelementptr inbounds i32, i32* %C, i64 %idxprom1 - %1 = load i32, i32* %arrayidx2, align 4 - %add3 = add nsw i32 %0, %1 - %idxprom4 = sext i32 %i.02 to i64 - %arrayidx5 = getelementptr inbounds i32, i32* %A, i64 %idxprom4 - store i32 %add3, i32* %arrayidx5, align 4 - br label %for.inc - -for.inc: ; preds = %for.body - %inc = add nsw i32 %i.02, 1 - %cmp = icmp slt i32 %inc, %N - br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge - -for.cond.for.end_crit_edge: ; preds = %for.inc - br label %for.end - -for.end: ; preds = %for.cond.for.end_crit_edge, %entry - ret void -} -- 2.11.0