[llvm] Allow folding icmp eq (add X, C2), C when there is more than one-use when we can compute the range (PR #144566)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 18 17:45:02 PDT 2025
AZero13 wrote:
> > > > @topperc this is having too many side effects. I think we should do what I originally did for now and then I will invest working on a proper fix because this is not going to be easily done in one PR
> > >
> > >
> > > Ok. Is there a known workload that benefits from this?
> >
> >
> > Plenty. Let me ask @dtcxzyw
>
> X86/RISCV/ARM/AArch64 all generates the same code for these two IR functions. Do I need a larger test case to show improved code generation?
>
> ```
> define i32 @add_check_zero(i32 %num) {
> %add = add i32 %num, 1
> %cmp = icmp eq i32 %add, 0
> %cond = select i1 %cmp, i32 -1, i32 %add
> ret i32 %cond
> }
>
> define i32 @add_check_zero_opt(i32 %num) {
> %a = call i32 @llvm.uadd.sat.i32(i32 %num, i32 1)
> ret i32 %a
> }
> ```
It's more about the IR optimization, not just codegen.
https://github.com/llvm/llvm-project/pull/144566
More information about the llvm-commits
mailing list