[llvm] r288725 - [SCCP] Remove manual folding of terminator instructions.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 5 18:37:11 PST 2016


Reverting for now (r288759).

On Mon, Dec 5, 2016 at 6:34 PM, NAKAMURA Takumi <geek4civic at gmail.com> wrote:
> It's failing with -Asserts. Investigating.
> http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/46076
>
> On Tue, Dec 6, 2016 at 8:14 AM Davide Italiano via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: davide
>> Date: Mon Dec  5 17:04:21 2016
>> New Revision: 288725
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=288725&view=rev
>> Log:
>> [SCCP] Remove manual folding of terminator instructions.
>>
>> There are two cases handled here:
>> 1) a branch on undef
>> 2) a switch with an undef condition.
>>
>> Both cases are currently handled by ResolvedUndefsIn. If we have
>> a branch on undef, we force its value to false (which is trivially
>> foldable). If we have a switch on undef, we force to the first
>> constant (which is also foldable).
>>
>> 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=288725&r1=288724&r2=288725&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Mon Dec  5 17:04:21 2016
>> @@ -1828,33 +1828,8 @@ static bool runIPSCCP(Module &M, const D
>>          // Ignore blockaddress users; BasicBlock's dtor will handle them.
>>          if (!I) continue;
>>
>> -        bool Folded = ConstantFoldTerminator(I->getParent());
>> -        if (!Folded) {
>> -          // The constant folder may not have been able to fold the
>> terminator
>> -          // if this is a branch or switch on undef.  Fold it manually as
>> a
>> -          // branch to the first successor.
>> -#ifndef NDEBUG
>> -          if (auto *BI = dyn_cast<BranchInst>(I)) {
>> -            assert(BI->isConditional() &&
>> isa<UndefValue>(BI->getCondition()) &&
>> -                   "Branch should be foldable!");
>> -          } else if (auto *SI = dyn_cast<SwitchInst>(I)) {
>> -            assert(isa<UndefValue>(SI->getCondition()) && "Switch should
>> fold");
>> -          } else {
>> -            llvm_unreachable("Didn't fold away reference to block!");
>> -          }
>> -#endif
>> -
>> -          // Make this an uncond branch to the first successor.
>> -          TerminatorInst *TI = I->getParent()->getTerminator();
>> -          BranchInst::Create(TI->getSuccessor(0), TI);
>> -
>> -          // Remove entries in successor phi nodes to remove edges.
>> -          for (unsigned i = 1, e = TI->getNumSuccessors(); i != e; ++i)
>> -            TI->getSuccessor(i)->removePredecessor(TI->getParent());
>> -
>> -          // Remove the old terminator.
>> -          TI->eraseFromParent();
>> -        }
>> +        assert(ConstantFoldTerminator(I->getParent()) &&
>> +          "Terminator should've been folded");
>>        }
>>
>>        // Finally, delete the basic block.
>>
>>
>> _______________________________________________
>> 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