We already support pulling through an add with constant RHS. We can do the same for subtract.

# Details

Details

# Diff Detail

Diff Detail

- Repository
- rL LLVM

### Event Timeline

Comment Actions

For reference, http://rise4fun.com/Alive/8l5 .

This transform throws nsw/nuw flags; can we preserve them in some situations?

lib/Transforms/InstCombine/InstCombineShifts.cpp | ||
---|---|---|

525 ↗ | (On Diff #110137) | Maybe add a comment writing out the transform in mathematical terms? (e.g. "2 * (A - B)" -> "2 * A - 2 * B"). |

test/Transforms/InstCombine/sub.ll | ||

1082 ↗ | (On Diff #110137) | This could use a couple more tests, to specifically show the transform this patch adds. |

Comment Actions

Add a simpler test case and a more mathematical comment.

Not sure how to preserve NSW/NUW without calling computeKnownBits. Any ideas?

Comment Actions

LGTM, with one small question.

lib/Transforms/InstCombine/InstCombineShifts.cpp | ||
---|---|---|

518 ↗ | (On Diff #110256) | It looks like this can match a vector? If it can, please add a vector testcase. |