This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Support folding a subtract with a constant LHS into a phi node
ClosedPublic

Authored by craig.topper on Apr 4 2017, 4:56 PM.

Details

Summary

We currently only support folding a subtract into a select but not a PHI. This fixes that.

I had to fix an assumption in FoldOpIntoPhi that assumed the PHI node was always in operand 0. Now we pass it in like we do for FoldOpIntoSelect. But we still require some dancing to find the Constant when we create the BinOp or ConstantExpr. This is based code is similar to what we do for selects.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 4 2017, 4:56 PM
spatel accepted this revision.Apr 14 2017, 7:46 AM

LGTM. See inline comments for a couple of minor bits.

lib/Transforms/InstCombine/InstCombineInternal.h
565

Since we're changing the signature, how about fixing the capitalization to current fashion as a clean-up ?
foldOpIntoPhi()
foldOpIntoSelect()

test/Transforms/InstCombine/sub.ll
749–754

Best to make this an NFC change before this commit.

This revision is now accepted and ready to land.Apr 14 2017, 7:46 AM
This revision was automatically updated to reflect the committed changes.

Just FYI, i'm about to post a patch to newgvn (just doing some debugging) which will do equivalence between phi of ops and op of phis, in value numbering (which makes them susceptible for later simplification)

It gets these cases already (and i suspect, a lot of instcombine cases)
For the initial version, it is limited to insertion in cases where the phi nodes end up constants for simplicity.
(Which is enough to catch all of these cases)