Skip to content

Commit dee9d85

Browse files
committed
[InstCombine] Use m_NotForbidPoison when folding (X u< Y) ? -1 : (~X + Y) --> uadd.sat(~X, Y)
1 parent a9958c4 commit dee9d85

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ static Value *canonicalizeSaturatedAdd(ICmpInst *Cmp, Value *TVal, Value *FVal,
10511051
// Strictness of the comparison is irrelevant.
10521052
X = Cmp0;
10531053
Y = Cmp1;
1054-
if (match(FVal, m_c_Add(m_Not(m_Specific(X)), m_Specific(Y)))) {
1054+
if (match(FVal, m_c_Add(m_NotForbidPoison(m_Specific(X)), m_Specific(Y)))) {
10551055
// (X u< Y) ? -1 : (~X + Y) --> uadd.sat(~X, Y)
10561056
// (X u< Y) ? -1 : (Y + ~X) --> uadd.sat(Y, ~X)
10571057
BinaryOperator *BO = cast<BinaryOperator>(FVal);

llvm/test/Transforms/InstCombine/saturating-add-sub.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,9 @@ define <2 x i32> @uadd_sat_not_ugt_commute_add(<2 x i32> %x, <2 x i32> %yp) {
18931893
define <2 x i32> @uadd_sat_not_ugt_commute_add_partial_poison(<2 x i32> %x, <2 x i32> %yp) {
18941894
; CHECK-LABEL: @uadd_sat_not_ugt_commute_add_partial_poison(
18951895
; CHECK-NEXT: [[NOTX:%.*]] = xor <2 x i32> [[X:%.*]], <i32 -1, i32 poison>
1896-
; CHECK-NEXT: [[R:%.*]] = call <2 x i32> @llvm.uadd.sat.v2i32(<2 x i32> [[YP:%.*]], <2 x i32> [[NOTX]])
1896+
; CHECK-NEXT: [[A:%.*]] = add nuw <2 x i32> [[YP:%.*]], [[NOTX]]
1897+
; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[YP]], [[X]]
1898+
; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C]], <2 x i32> <i32 -1, i32 -1>, <2 x i32> [[A]]
18971899
; CHECK-NEXT: ret <2 x i32> [[R]]
18981900
;
18991901
%notx = xor <2 x i32> %x, <i32 -1, i32 poison>

0 commit comments

Comments
 (0)