[llvm] r315329 - Revert "[SCCP] Propagate integer range info for parameters in IPSCCP."
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 10 21:31:35 PDT 2017
Do you have a repro?
On Tue, Oct 10, 2017 at 9:37 AM, Bruno Cardoso Lopes via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: bruno
> Date: Tue Oct 10 09:37:57 2017
> New Revision: 315329
>
> URL: http://llvm.org/viewvc/llvm-project?rev=315329&view=rev
> Log:
> Revert "[SCCP] Propagate integer range info for parameters in IPSCCP."
>
> This reverts commit r315288. This is part of fixing segfault introduced
> in:
>
> http://green.lab.llvm.org/green/job/clang-stage2-configure-Rlto/21675/
>
> Removed:
> llvm/trunk/test/Transforms/SCCP/ip-constan-ranges.ll
> Modified:
> llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=315329&r1=315328&r2=315329&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Tue Oct 10 09:37:57 2017
> @@ -27,7 +27,6 @@
> #include "llvm/Analysis/ConstantFolding.h"
> #include "llvm/Analysis/GlobalsModRef.h"
> #include "llvm/Analysis/TargetLibraryInfo.h"
> -#include "llvm/Analysis/ValueLattice.h"
> #include "llvm/IR/CallSite.h"
> #include "llvm/IR/Constants.h"
> #include "llvm/IR/DataLayout.h"
> @@ -53,8 +52,6 @@ STATISTIC(NumDeadBlocks , "Number of bas
> STATISTIC(IPNumInstRemoved, "Number of instructions removed by IPSCCP");
> STATISTIC(IPNumArgsElimed ,"Number of arguments constant propagated by IPSCCP");
> STATISTIC(IPNumGlobalConst, "Number of globals found to be constant by IPSCCP");
> -STATISTIC(IPNumRangeInfoUsed, "Number of times constant range info was used by"
> - "IPSCCP");
>
> namespace {
> /// LatticeVal class - This class represents the different lattice values that
> @@ -156,14 +153,6 @@ public:
> Val.setInt(forcedconstant);
> Val.setPointer(V);
> }
> -
> - ValueLatticeElement toValueLattice() const {
> - if (isOverdefined())
> - return ValueLatticeElement::getOverdefined();
> - if (isConstant())
> - return ValueLatticeElement::get(getConstant());
> - return ValueLatticeElement();
> - }
> };
> } // end anonymous namespace.
>
> @@ -180,8 +169,6 @@ class SCCPSolver : public InstVisitor<SC
> const TargetLibraryInfo *TLI;
> SmallPtrSet<BasicBlock*, 8> BBExecutable; // The BBs that are executable.
> DenseMap<Value*, LatticeVal> ValueState; // The state each value is in.
> - // The state each parameter is in.
> - DenseMap<Value *, ValueLatticeElement> ParamState;
>
> /// StructValueState - This maintains ValueState for values that have
> /// StructType, for example for formal arguments, calls, insertelement, etc.
> @@ -303,15 +290,10 @@ public:
> return StructValues;
> }
>
> - ValueLatticeElement getLatticeValueFor(Value *V) {
> - if (ParamState.count(V) == 0) {
> - DenseMap<Value *, LatticeVal>::const_iterator I = ValueState.find(V);
> - assert(I != ValueState.end() &&
> - "V not found in ValueState nor Paramstate map!");
> - ParamState[V] = I->second.toValueLattice();
> - }
> -
> - return ParamState[V];
> + LatticeVal getLatticeValueFor(Value *V) const {
> + DenseMap<Value*, LatticeVal>::const_iterator I = ValueState.find(V);
> + assert(I != ValueState.end() && "V is not in valuemap!");
> + return I->second;
> }
>
> /// getTrackedRetVals - Get the inferred return value map.
> @@ -444,15 +426,6 @@ private:
> return LV;
> }
>
> - ValueLatticeElement &getParamState(Value *V) {
> - assert(!V->getType()->isStructTy() && "Should use getStructValueState");
> -
> - if (ParamState.count(V) == 0)
> - ParamState[V] = getValueState(V).toValueLattice();
> -
> - return ParamState[V];
> - }
> -
> /// getStructValueState - Return the LatticeVal object that corresponds to the
> /// value/field pair. This function handles the case when the value hasn't
> /// been seen yet by properly seeding constants etc.
> @@ -1189,9 +1162,6 @@ CallOverdefined:
> mergeInValue(getStructValueState(&*AI, i), &*AI, CallArg);
> }
> } else {
> - // Most other parts of the Solver still only use the simpler value
> - // lattice, so we propagate changes for parameters to both lattices.
> - getParamState(&*AI).mergeIn(getValueState(*CAI).toValueLattice(), DL);
> mergeInValue(&*AI, getValueState(*CAI));
> }
> }
> @@ -1587,44 +1557,6 @@ bool SCCPSolver::ResolvedUndefsIn(Functi
> return false;
> }
>
> -static bool tryToReplaceWithConstantRange(SCCPSolver &Solver, Value *V) {
> - bool Changed = false;
> - if (!V->getType()->isIntegerTy())
> - return false;
> -
> - const ValueLatticeElement &IV = Solver.getLatticeValueFor(V);
> - if (IV.isOverdefined())
> - return false;
> -
> - // Currently we only use range information for integer values.
> - if (!(V->getType()->isIntegerTy() && IV.isConstantRange()))
> - return false;
> -
> - for (auto &Use : V->uses()) {
> - auto *Icmp = dyn_cast<ICmpInst>(Use.getUser());
> - if (!Icmp)
> - continue;
> -
> - auto A = Solver.getLatticeValueFor(Icmp->getOperand(0));
> - auto B = Solver.getLatticeValueFor(Icmp->getOperand(1));
> - Constant *C = nullptr;
> - if (A.satisfiesPredicate(Icmp->getPredicate(), B))
> - C = ConstantInt::getTrue(Icmp->getType());
> - else if (A.satisfiesPredicate(Icmp->getInversePredicate(), B))
> - C = ConstantInt::getFalse(Icmp->getType());
> -
> - if (C) {
> - Icmp->replaceAllUsesWith(C);
> - DEBUG(dbgs() << "Replacing " << *Icmp << " with " << *C
> - << ", because of range information " << A << " " << B
> - << "\n");
> - Icmp->eraseFromParent();
> - Changed = true;
> - }
> - }
> - return Changed;
> -}
> -
> static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) {
> Constant *Const = nullptr;
> if (V->getType()->isStructTy()) {
> @@ -1641,19 +1573,10 @@ static bool tryToReplaceWithConstant(SCC
> }
> Const = ConstantStruct::get(ST, ConstVals);
> } else {
> - const ValueLatticeElement &IV = Solver.getLatticeValueFor(V);
> + LatticeVal IV = Solver.getLatticeValueFor(V);
> if (IV.isOverdefined())
> return false;
> -
> - if (IV.isConstantRange()) {
> - if (IV.getConstantRange().isSingleElement())
> - Const =
> - ConstantInt::get(V->getType(), IV.asConstantInteger().getValue());
> - else
> - return false;
> - } else
> - Const =
> - IV.isConstant() ? IV.getConstant() : UndefValue::get(V->getType());
> + Const = IV.isConstant() ? IV.getConstant() : UndefValue::get(V->getType());
> }
> assert(Const && "Constant is nullptr here!");
> DEBUG(dbgs() << " Constant: " << *Const << " = " << *V << '\n');
> @@ -1893,17 +1816,12 @@ static bool runIPSCCP(Module &M, const D
> if (F.isDeclaration())
> continue;
>
> - if (Solver.isBlockExecutable(&F.front())) {
> + if (Solver.isBlockExecutable(&F.front()))
> for (Function::arg_iterator AI = F.arg_begin(), E = F.arg_end(); AI != E;
> - ++AI) {
> + ++AI)
> if (!AI->use_empty() && tryToReplaceWithConstant(Solver, &*AI))
> ++IPNumArgsElimed;
>
> - if (!AI->use_empty() && tryToReplaceWithConstantRange(Solver, &*AI))
> - ++IPNumRangeInfoUsed;
> - }
> - }
> -
> for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
> if (!Solver.isBlockExecutable(&*BB)) {
> DEBUG(dbgs() << " BasicBlock Dead:" << *BB);
>
> Removed: llvm/trunk/test/Transforms/SCCP/ip-constan-ranges.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SCCP/ip-constan-ranges.ll?rev=315328&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/SCCP/ip-constan-ranges.ll (original)
> +++ llvm/trunk/test/Transforms/SCCP/ip-constan-ranges.ll (removed)
> @@ -1,117 +0,0 @@
> -; RUN: opt < %s -ipsccp -S | FileCheck %s
> -
> -; Constant range for %a is [1, 48) and for %b is [301, 1000)
> -; CHECK-LABEL: f1
> -; CHECK-NOT: icmp
> -; CHECK: %a.1 = select i1 false, i32 1, i32 2
> -; CHECK: %b.1 = select i1 true, i32 1, i32 2
> -; CHECK: %a.2 = select i1 false, i32 1, i32 2
> -; CHECK: %b.2 = select i1 true, i32 1, i32 2
> -define internal i32 @f1(i32 %a, i32 %b) {
> -entry:
> - %cmp.a = icmp sgt i32 %a, 300
> - %cmp.b = icmp sgt i32 %b, 300
> - %cmp.a2 = icmp ugt i32 %a, 300
> - %cmp.b2 = icmp ugt i32 %b, 300
> -
> - %a.1 = select i1 %cmp.a, i32 1, i32 2
> - %b.1 = select i1 %cmp.b, i32 1, i32 2
> - %a.2 = select i1 %cmp.a2, i32 1, i32 2
> - %b.2 = select i1 %cmp.b2, i32 1, i32 2
> - %res1 = add i32 %a.1, %b.1
> - %res2 = add i32 %a.2, %b.2
> - %res3 = add i32 %res1, %res2
> - ret i32 %res3
> -}
> -
> -; Constant range for %x is [47, 302)
> -; CHECK-LABEL: f2
> -; CHECK: %cmp = icmp sgt i32 %x, 300
> -; CHECK: %res1 = select i1 %cmp, i32 1, i32 2
> -; CHECK-NEXT: %res2 = select i1 true, i32 3, i32 4
> -; CHECK-NEXT: %res3 = select i1 true, i32 5, i32 6
> -; CHECK-NEXT: %res4 = select i1 %cmp4, i32 3, i32 4
> -; CHECK-NEXT: %res5 = select i1 true, i32 5, i32 6
> -define internal i32 @f2(i32 %x) {
> -entry:
> - %cmp = icmp sgt i32 %x, 300
> - %cmp2 = icmp ne i32 %x, 10
> - %cmp3 = icmp sge i32 %x, 47
> - %cmp4 = icmp ugt i32 %x, 300
> - %cmp5 = icmp uge i32 %x, 47
> - %res1 = select i1 %cmp, i32 1, i32 2
> - %res2 = select i1 %cmp2, i32 3, i32 4
> - %res3 = select i1 %cmp3, i32 5, i32 6
> - %res4 = select i1 %cmp4, i32 3, i32 4
> - %res5 = select i1 %cmp5, i32 5, i32 6
> -
> - %res6 = add i32 %res1, %res2
> - %res7 = add i32 %res3, %res4
> - %res = add i32 %res6, %res5
> - ret i32 %res
> -}
> -
> -define i32 @caller1() {
> -entry:
> - %call1 = tail call i32 @f1(i32 1, i32 301)
> - %call2 = tail call i32 @f1(i32 47, i32 999)
> - %call3 = tail call i32 @f2(i32 47)
> - %call4 = tail call i32 @f2(i32 301)
> - %res = add nsw i32 %call1, %call2
> - %res.1 = add nsw i32 %res, %call3
> - %res.2 = add nsw i32 %res.1, %call4
> - ret i32 %res.2
> -}
> -
> -; x is overdefined, because constant ranges are only used for parameter
> -; values.
> -; CHECK-LABEL: f3
> -; CHECK: %cmp = icmp sgt i32 %x, 300
> -; CHECK: %res = select i1 %cmp, i32 1, i32 2
> -; CHECK: ret i32 %res
> -define internal i32 @f3(i32 %x) {
> -entry:
> - %cmp = icmp sgt i32 %x, 300
> - %res = select i1 %cmp, i32 1, i32 2
> - ret i32 %res
> -}
> -
> -; The phi node could be converted in a ConstantRange.
> -define i32 @caller2(i1 %cmp) {
> -entry:
> - br i1 %cmp, label %if.true, label %end
> -
> -if.true:
> - br label %end
> -
> -end:
> - %res = phi i32 [ 0, %entry], [ 1, %if.true ]
> - %call1 = tail call i32 @f3(i32 %res)
> - ret i32 %call1
> -}
> -
> -; CHECK-LABEL: f4
> -; CHECK: %cmp = icmp sgt i32 %x, 300
> -; CHECK: %res = select i1 %cmp, i32 1, i32 2
> -; CHECK: ret i32 %res
> -define internal i32 @f4(i32 %x) {
> -entry:
> - %cmp = icmp sgt i32 %x, 300
> - %res = select i1 %cmp, i32 1, i32 2
> - ret i32 %res
> -}
> -
> -; ICmp could introduce bounds on ConstantRanges.
> -define i32 @caller3(i32 %x) {
> -entry:
> - %cmp = icmp sgt i32 %x, 300
> - br i1 %cmp, label %if.true, label %end
> -
> -if.true:
> - %x.1 = tail call i32 @f4(i32 %x)
> - br label %end
> -
> -end:
> - %res = phi i32 [ 0, %entry], [ %x.1, %if.true ]
> - ret i32 %res
> -}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
--
Davide
"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare
More information about the llvm-commits
mailing list