[llvm] [InstCombine]: Replace overflow calculation with intrinsic (PR #168195)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 14 01:32:59 PDT 2026
mikaseianatsu wrote:
I noticed the same pattern also appears in vector form, but it is not folded yet.
Scalar:
```llvm
define i1 @src(i16 %x, i16 %y) {
%1 = sext i16 %x to i32
%2 = sext i16 %y to i32
%3 = add i32 %1, -32768
%4 = sub i32 %3, %2
%5 = icmp ult i32 %4, -65536
ret i1 %5
}
```
can be optimized to:
```llvm
define i1 @tgt(i16 %x, i16 %y) {
%1 = call { i16, i1 } @llvm.ssub.with.overflow.i16(i16 %x, i16 %y)
%2 = extractvalue { i16, i1 } %1, 1
ret i1 %2
}
```
But the vector version:
```llvm
define <8 x i1> @src(<8 x i16> %0, <8 x i16> %1) {
entry:
%2 = sext <8 x i16> %0 to <8 x i32>
%3 = sext <8 x i16> %1 to <8 x i32>
%4 = add <8 x i32> %2, splat (i32 -32768)
%5 = sub <8 x i32> %4, %3
%6 = icmp ult <8 x i32> %5, splat (i32 -65536)
ret <8 x i1> %6
}
```
currently remains unchanged
So this pattern seems to be recognized for scalar, but not yet for vectors.
https://github.com/llvm/llvm-project/pull/168195
More information about the llvm-commits
mailing list