This is an archive of the discontinued LLVM Phabricator instance.

[instcombine] PRE freeze to only potentially posion/undef operand of phi
ClosedPublic

Authored by reames on Oct 13 2021, 10:14 AM.

Details

Summary

This extends the foldOpIntoPhi code used when visiting a freeze user of a phi to allow any non-undef/poison operand as opposed to only non-undef/poison constants.

While this works, I'm not sure this is the right way to solve this problem. We're replacing a very cheap check with a bounded search of each phi operand, which has potential compile time implications. (@nikic - Could you help quantify?)

This routine is fairly limited. I went looking for a stronger routine (because really we're just folding the phi away when inst-simplify can prove there's an existing value for all but one operand), but was shocked not to find one (anywhere). I've got a toy binop test case that shows we entirely miss the corresponding opportunity at O3.

I'm really curious on others take here.

Diff Detail

Event Timeline

reames created this revision.Oct 13 2021, 10:14 AM
reames requested review of this revision.Oct 13 2021, 10:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 13 2021, 10:14 AM
nikic accepted this revision.Oct 13 2021, 11:54 AM

LGTM

While this works, I'm not sure this is the right way to solve this problem. We're replacing a very cheap check with a bounded search of each phi operand, which has potential compile time implications. (@nikic - Could you help quantify?)

Not seeing a compile-time impact from this. Generally freeze is sufficiently rare that we don't need to be overly concerned with compile-time at this point.

This routine is fairly limited. I went looking for a stronger routine (because really we're just folding the phi away when inst-simplify can prove there's an existing value for all but one operand), but was shocked not to find one (anywhere). I've got a toy binop test case that shows we entirely miss the corresponding opportunity at O3.

So you're basically looking for this transform, but replacing ConstFold with InstSimplify? Would be possible, but I think this would be fairly expensive.

This revision is now accepted and ready to land.Oct 13 2021, 11:54 AM
This revision was landed with ongoing or failed builds.Oct 13 2021, 1:57 PM
This revision was automatically updated to reflect the committed changes.