This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] reduce mul operands based on undemanded high bits
ClosedPublic

Authored by spatel on Feb 9 2022, 12:50 PM.

Details

Summary

We already do this in SDAG, but mul was left out of the fold for unused high bits in IR.
The high bits of a mul's operands do not change the low bits of the result:
https://alive2.llvm.org/ce/z/XRj5Ek

Verify some test diffs to confirm that they are correct:
https://alive2.llvm.org/ce/z/y_W8DW
https://alive2.llvm.org/ce/z/7DM5uf
https://alive2.llvm.org/ce/z/GDiHCK

This gets a fold that was presumed not possible in D114272:
https://alive2.llvm.org/ce/z/tAN-WY

Removing nsw/nuw is needed for general correctness (and is also done in the codegen version), but we might be able to recover more of those with better analysis.

Diff Detail

Event Timeline

spatel created this revision.Feb 9 2022, 12:50 PM
spatel requested review of this revision.Feb 9 2022, 12:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2022, 12:50 PM
lebedev.ri accepted this revision.Feb 9 2022, 1:03 PM

LGTM, thank you.
The same is true for and/or/xor.

This revision is now accepted and ready to land.Feb 9 2022, 1:03 PM
spatel added a comment.Feb 9 2022, 1:45 PM

LGTM, thank you.

Thanks!

The same is true for and/or/xor.

Yes - those are more general, Any undemanded bit (not just high bits) in the result is also undemanded in the operands. Those appear to be handled optimally already.

This revision was landed with ongoing or failed builds.Feb 10 2022, 5:11 AM
This revision was automatically updated to reflect the committed changes.