This is an archive of the discontinued LLVM Phabricator instance.

[SCCP] Remove manual folding of terminator instructions.
ClosedPublic

Authored by trentxintong on Feb 25 2017, 2:10 PM.

Details

Summary

BranchInst, SwitchInst (with non-default case) with Undef as input is not
possible at this point. As we always default-fold terminator to one target in
ResolvedUndefsIn and set the input accordingly.

So we should only have constantint/blockaddress here.

If ConstantFoldTerminator fails, that could mean 2 things.

  1. ConstantFoldTerminator is doing something unexpected, i.e. not folding on constantint

or blockaddress and not making blocks that should be dead dead.

  1. This is not a terminator on constantint or blockaddress. Its on a constant or

overdefined, then this block should not be dead.

In both cases, we should assert.

Diff Detail

Repository
rL LLVM

Event Timeline

trentxintong created this revision.Feb 25 2017, 2:10 PM

I understand there was a previous attempt at removing these code before and it caused a build break.

8ea5797013603a088dd6be6ad49d1a117f1955e2
[SCCP] Remove manual folding of terminator instructions.

4b6e5ecd86de0863546ab2ecf3a8f979f0d1a8a0
Revert "[SCCP] Remove manual folding of terminator instructions."
This reverts commit r288725 as it broke a bot.

I think the problem might be with the ConstantFoldTerminator in the assert(), should not
assert() be null'ed in release build ?

With this patch, I ran LTO on CPU2006 C/C++ benchmarks locally, they compiled and ran fine.

I also checked when the manual folding code is added, it is added in
ddaaa374879f2f736f7bfa20f4b25202fcb85708 at which time we only mark an edge executable
when its branching on an undef, but not setting its value to a constant.

davide accepted this revision.Feb 25 2017, 6:02 PM

I actually forgot to recommit this one :(
The issue with the original patch was that I folded the call inside the assert so ConstantFoldTerminator() was compiled away in !DEBUG mode.
Oh, well. Your reasoning is correct (actually, was my original reasoning when I committed the patch).

This revision is now accepted and ready to land.Feb 25 2017, 6:02 PM
This revision was automatically updated to reflect the committed changes.

@davide Thanks for taking a quick look !