This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Support (sub (sext x), (sext y)) --> (sext (sub x, y)) and (sub (zext x), (zext y)) --> (zext (sub x, y))
ClosedPublic

Authored by craig.topper on Sep 14 2018, 12:01 AM.

Details

Summary

If the sub doesn't overflow in the original type we can move it above the sext/zext.

This is similar to what we do for add. The overflow checking for sub is currently weaker than add, so the test cases are constructed for what is supported.

Diff Detail

Event Timeline

craig.topper created this revision.Sep 14 2018, 12:01 AM

Logic seems right, but we already had a big pile of repeated code.
I think we can handle sub the same way as add/mul after:
rL342292
The only extra work will be swapping the constant operand to LHS for sub?

Rebase to use the code from r342292.

spatel accepted this revision.Sep 15 2018, 6:42 AM

LGTM - but please add at least one negative test where the math actually could overflow, so we verify that the value tracking is in place.

This revision is now accepted and ready to land.Sep 15 2018, 6:42 AM
This revision was automatically updated to reflect the committed changes.