[llvm] [InstCombine] Fold usub_sat((sub nuw C1, A), C2) to usub_sat(C1 - C2, A) or 0 (PR #82280)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 7 13:56:22 PST 2024
elhewaty wrote:
@nikic, Sorry I will update it now
> * vector test
Do we need the vector test?
> * test with commuted sub like (sub nuw i32 %a, 12), proof: https://alive2.llvm.org/ce/z/kVXDgW
For this test I think the optimizer converts sub to add and then add a negative number, Is there is a way to match additions with over flow like this:
```
%res = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %c1, i8 %c2)
%overflow = extractvalue {i8, i1} %res, 1
%notoverflow = xor i1 %overflow, -1
call void @llvm.assume(i1 %notoverflow)
%add = sub nuw i8 %a, %c1
%cond = call i8 @llvm.usub.sat.i8(i8 %add, i8 %c2)
ret i8 %cond
```
https://github.com/llvm/llvm-project/pull/82280
More information about the llvm-commits
mailing list