This is an archive of the discontinued LLVM Phabricator instance.

[SCCP] Resolve indirect branch target when possible.
ClosedPublic

Authored by trentxintong on Feb 23 2017, 7:29 PM.

Details

Summary

Resolve indirect branch target when possible.
This potentially eliminates more basicblocks and result in better evaluation for phi and other things.

Diff Detail

Repository
rL LLVM

Event Timeline

trentxintong created this revision.Feb 23 2017, 7:29 PM
davide added inline comments.Feb 23 2017, 8:24 PM
lib/Transforms/Scalar/SCCP.cpp
1531–1548 ↗(On Diff #89606)

I'm very wary of adding more code here, as it caused a fair amount of pain in the past. This, tho, seems to be in line with what was already there.

1895–1896 ↗(On Diff #89606)

Can this assertion ever fire?

trentxintong added inline comments.Feb 24 2017, 10:10 AM
lib/Transforms/Scalar/SCCP.cpp
1531–1548 ↗(On Diff #89606)

I feel getting rid of this undef resolver is the way to go for SCCP. When I read this pass, I do not feel very good about how undef is resolved, especially the ordering terminators and its input is resolved does not seem to be bullet-proof. And it does have bugs.

However this is what we need to get indirectbr simplification working for now =).

1895–1896 ↗(On Diff #89606)

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

SwitchInst with only default-case is a slightly different, its input may not have resolved to constantint/blockaddress or overdefined state. But in such case, we make default-target always executable.

So we should only have constantint/blockaddress or constant(not int nor blockaddress)/overdefined here.

Maybe the check we really do is assert(Fold && "Must be able to fold terminator on constantint or blockaddress"); If this 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.
  2. 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.

davide added inline comments.Feb 24 2017, 10:34 AM
lib/Transforms/Scalar/SCCP.cpp
1531–1548 ↗(On Diff #89606)

I really agree, and in fact I discussed this on the mailing lists (and with Dan Berlin and David Majnemer). I have a patch for that, but needs some performance testing. If you care about this, maybe you can run on your benchmarks? (I'm going to clean up the branch and send the patch to you).

@davide I am more than happy to run your patch on some Facebook internal server workloads.

davide edited edge metadata.Mar 1 2017, 11:02 PM

I really apologize for the delay in providing you the patch. I'm at GDC this week and that limits my ability to work on LLVM upstream things. I will provide the patch to you next week, and if I don't because I forget, feel free to ping me again.

@davide do you think its OK to land this patch first and I will help you to run your patch once you have it ready ? Thanks !

davide accepted this revision.Apr 9 2017, 4:37 PM
This revision is now accepted and ready to land.Apr 9 2017, 4:37 PM
This revision was automatically updated to reflect the committed changes.