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.

Differential D52075

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

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

Details

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

- Repository
- rL LLVM

Comment Actions

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?

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.