<div dir="ltr">Hi Davide,<div><br></div><div>We're seeing large compile-time regressions with this change and LTO when compiling spec2000/2006. For example, the compile-time of spec2000/crafty roughly doubles. Would you mind taking a look? We're compiling with "-Ofast -flto -fuse-ld=gold -mcpu=kryo". Please let me know if you're unable to reproduce. Thanks!</div><div><br></div><div>-- Matt</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 13, 2016 at 10:34 PM, Davide Italiano via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, Jul 13, 2016 at 6:51 PM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>> wrote:<br>
> On Wed, Jul 13, 2016 at 6:27 PM, Davide Italiano via llvm-commits<br>
> <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
>><br>
>> Author: davide<br>
>> Date: Wed Jul 13 20:27:29 2016<br>
>> New Revision: 275357<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=275357&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=275357&view=rev</a><br>
>> Log:<br>
>> [SCCP] Generalize tryToReplaceInstWithConstant to work also with<br>
>> arguments.<br>
>><br>
>> Modified:<br>
>>     llvm/trunk/lib/Transforms/Scalar/SCCP.cpp<br>
>><br>
>> Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=275357&r1=275356&r2=275357&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=275357&r1=275356&r2=275357&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)<br>
>> +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Wed Jul 13 20:27:29 2016<br>
>> @@ -1510,16 +1510,16 @@ bool SCCPSolver::ResolvedUndefsIn(Functi<br>
>>    return false;<br>
>>  }<br>
>><br>
>> -static bool tryToReplaceInstWithConstant(SCCPSolver Solver, Instruction<br>
>> *Inst,<br>
>> -                                         bool shouldEraseFromParent) {<br>
>> +template <typename ArgOrInst><br>
>> +static bool tryToReplaceWithConstant(SCCPSolver Solver, ArgOrInst *AI) {<br>
><br>
><br>
> Can you just use a Value* here?<br>
><br>
<br>
</div></div>Sure, I'll change that.<br>
<div><div class="h5"><br>
>><br>
>>    Constant *Const = nullptr;<br>
>> -  if (Inst->getType()->isStructTy()) {<br>
>> -    std::vector<LatticeVal> IVs = Solver.getStructLatticeValueFor(Inst);<br>
>> +  if (AI->getType()->isStructTy()) {<br>
>> +    std::vector<LatticeVal> IVs = Solver.getStructLatticeValueFor(AI);<br>
>>      if (std::any_of(IVs.begin(), IVs.end(),<br>
>>                      [](LatticeVal &LV) { return LV.isOverdefined(); }))<br>
>>        return false;<br>
>>      std::vector<Constant *> ConstVals;<br>
>> -    StructType *ST = dyn_cast<StructType>(Inst->getType());<br>
>> +    StructType *ST = dyn_cast<StructType>(AI->getType());<br>
>>      for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) {<br>
>>        LatticeVal V = IVs[i];<br>
>>        ConstVals.push_back(V.isConstant()<br>
>> @@ -1528,18 +1528,23 @@ static bool tryToReplaceInstWithConstant<br>
>>      }<br>
>>      Const = ConstantStruct::get(ST, ConstVals);<br>
>>    } else {<br>
>> -    LatticeVal IV = Solver.getLatticeValueFor(Inst);<br>
>> +    LatticeVal IV = Solver.getLatticeValueFor(AI);<br>
>>      if (IV.isOverdefined())<br>
>>        return false;<br>
>> -<br>
>> -    Const =<br>
>> -        IV.isConstant() ? IV.getConstant() :<br>
>> UndefValue::get(Inst->getType());<br>
>> +    Const = IV.isConstant() ? IV.getConstant() :<br>
>> UndefValue::get(AI->getType());<br>
>>    }<br>
>>    assert(Const && "Constant is nullptr here!");<br>
>> -  DEBUG(dbgs() << "  Constant: " << *Const << " = " << *Inst << '\n');<br>
>> +  DEBUG(dbgs() << "  Constant: " << *Const << " = " << *AI << '\n');<br>
>><br>
>>    // Replaces all of the uses of a variable with uses of the constant.<br>
>> -  Inst->replaceAllUsesWith(Const);<br>
>> +  AI->replaceAllUsesWith(Const);<br>
>> +  return true;<br>
>> +}<br>
>> +<br>
>> +static bool tryToReplaceInstWithConstant(SCCPSolver Solver, Instruction<br>
>> *Inst,<br>
>> +                                         bool shouldEraseFromParent) {<br>
>> +  if (!tryToReplaceWithConstant(Solver, Inst))<br>
>> +    return false;<br>
>><br>
>>    // Delete the instruction.<br>
>>    if (shouldEraseFromParent)<br>
>> @@ -1766,17 +1771,8 @@ static bool runIPSCCP(Module &M, const D<br>
>>          // TODO: Could use getStructLatticeValueFor to find out if the<br>
>> entire<br>
>>          // result is a constant and replace it entirely if so.<br>
>><br>
>> -        LatticeVal IV = Solver.getLatticeValueFor(&*AI);<br>
>> -        if (IV.isOverdefined()) continue;<br>
>> -<br>
>> -        Constant *CST = IV.isConstant() ?<br>
>> -        IV.getConstant() : UndefValue::get(AI->getType());<br>
>> -        DEBUG(dbgs() << "***  Arg " << *AI << " = " << *CST <<"\n");<br>
>> -<br>
>> -        // Replaces all of the uses of a variable with uses of the<br>
>> -        // constant.<br>
>> -        AI->replaceAllUsesWith(CST);<br>
>> -        ++IPNumArgsElimed;<br>
>> +        if (tryToReplaceWithConstant(Solver, &*AI))<br>
>> +          ++IPNumArgsElimed;<br>
>>        }<br>
>>      }<br>
><br>
><br>
> Testcase?<br>
><br>
<br>
</div></div>Sorry if I failed to mention on this commit, but this is NFC as we<br>
skip the replacement phase if the argument is of struct type (unless<br>
I'm missing something).<br>
My next patch, <a href="http://reviews.llvm.org/D22329" rel="noreferrer" target="_blank">http://reviews.llvm.org/D22329</a> , changes the behaviour<br>
and add test cases.<br>
<br>
<br>
Thanks for your review!<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Davide<br>
<br>
"There are no solved problems; there are only problems that are more<br>
or less solved" -- Henri Poincare<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>