Page MenuHomePhabricator

[InstCombine] eliminate sext and/or trunc if value has enough signbits
ClosedPublic

Authored by spatel on Thu, Jun 3, 7:35 AM.

Details

Summary

If we have enough signbits in a source value, we can skip an intermediate cast for a trunc+sext pair:
https://alive2.llvm.org/ce/z/A_mQt-

This is the original problem shown in:
https://llvm.org/PR49543

There's a test that shows we transformed what used to be a pair of shifts, so that suggests we could add another ComputeNumSignBits fold starting from a shift.

There does not appear to be any change in compile-time from the extra analysis:
https://llvm-compile-time-tracker.com/compare.php?from=3d2c9069dcafd0cbb641841aa3dd6e851fb7d760&to=b9513cdf2419704c7bb0c3a02a9ca06aae13d902&stat=instructions

Diff Detail

Event Timeline

spatel created this revision.Thu, Jun 3, 7:35 AM
spatel requested review of this revision.Thu, Jun 3, 7:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptThu, Jun 3, 7:35 AM

As per 5a654bfeab588715fa6d266a7789484850605a18, did you add the test where we'd form trunc?

spatel added a comment.Thu, Jun 3, 7:48 AM

As per 5a654bfeab588715fa6d266a7789484850605a18, did you add the test where we'd form trunc?

I didn't know you had tried this one already. :)
Yes - see tests "wide_source_matching_signbits" and "wide_source_not_matching_signbits".

This revision is now accepted and ready to land.Thu, Jun 3, 7:57 AM