[llvm] [InstCombine] Generalize zext(add X, -C) + C folding (PR #191723)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 02:57:11 PDT 2026


lfeng14 wrote:

I noticed that the patch includes test coverage for cases where the inner constant and outer constant are of different types (e.g., inner: -4 as i8, outer: 4 as i32):

```
  %inner = add i8 %or, -4     
  %z = zext i8 %inner to i32
  %r = add i32 %z, 4
```

This clearly demonstrates the optimization for the `zext(add(x, -const)) + const` pattern. However, I have one question: does this optimization also handle the symmetric pattern `zext(add(x, const)) + -const`?

If not, I would suggest adding a negative test case (or a TODO comment) to explicitly cover the reverse scenario, e.g.:

```
  %inner = add i8 %or, 4
  %z = zext i8 %inner to i32
  %r = add i32 %z, -4   ; outer constant is negative
```
  
  thank you

https://github.com/llvm/llvm-project/pull/191723


More information about the llvm-commits mailing list