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.
Paths
| Differential D52075
[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 TimelineComment Actions Logic seems right, but we already had a big pile of repeated code. Comment Actions 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 Closed by commit rL342335: [InstCombine] Support (sub (sext x), (sext y)) --> (sext (sub x, y)) and (sub… (authored by ctopper). · Explain WhySep 15 2018, 11:55 AM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 165655 llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/trunk/test/Transforms/InstCombine/narrow-math.ll
|