[PATCH] D125352: [InstCombine] fix sub(add(X,Y),umin(Y,Z)) --> add(X,usub.sat(Y,Z))
Chenbing.Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 11 19:16:32 PDT 2022
- Previous message: [PATCH] D125352: [InstCombine] fix sub(add(X,Y),umin(Y,Z)) --> add(X,usub.sat(Y,Z))
- Next message: [PATCH] D125352: [InstCombine] fix sub(add(X,Y),umin(Y,Z)) --> add(X,usub.sat(Y,Z))
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Chenbing.Zheng updated this revision to Diff 428837.
Chenbing.Zheng added a comment.
rebase and update tests
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125352/new/
https://reviews.llvm.org/D125352
Files:
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/sub-minmax.ll
Index: llvm/test/Transforms/InstCombine/sub-minmax.ll
===================================================================
--- llvm/test/Transforms/InstCombine/sub-minmax.ll
+++ llvm/test/Transforms/InstCombine/sub-minmax.ll
@@ -762,9 +762,7 @@
ret i8 %s
}
-;
-; TODO: sub(add(X,Y),umin(Y,Z)) --> add(X,usubsat(Y,Z))
-;
+; sub(add(X,Y),umin(Y,Z)) --> add(X,usubsat(Y,Z))
define i8 @sub_add_umin(i8 %x, i8 %y, i8 %z) {
; CHECK-LABEL: define {{[^@]+}}@sub_add_umin
@@ -782,7 +780,7 @@
define i8 @sub_add_umin_commute_umin(i8 %x, i8 %y, i8 %z) {
; CHECK-LABEL: define {{[^@]+}}@sub_add_umin_commute_umin
; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]], i8 [[Z:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[Z]], i8 [[Y]])
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[Y]], i8 [[Z]])
; CHECK-NEXT: [[S:%.*]] = add i8 [[TMP1]], [[X]]
; CHECK-NEXT: ret i8 [[S]]
;
@@ -808,7 +806,7 @@
define i8 @sub_add_umin_commute_add_umin(i8 %x, i8 %y, i8 %z) {
; CHECK-LABEL: define {{[^@]+}}@sub_add_umin_commute_add_umin
; CHECK-SAME: (i8 [[X:%.*]], i8 [[Y:%.*]], i8 [[Z:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[Z]], i8 [[Y]])
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[Y]], i8 [[Z]])
; CHECK-NEXT: [[S:%.*]] = add i8 [[TMP1]], [[X]]
; CHECK-NEXT: ret i8 [[S]]
;
Index: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -2031,14 +2031,17 @@
{
// sub(add(X,Y),umin(Y,Z)) --> add(X,usub.sat(Y,Z))
- // sub(add(X,Z),umin(Y,Z)) --> add(X,usub.sat(Y,Z))
+ // sub(add(X,Z),umin(Y,Z)) --> add(X,usub.sat(Z,Y))
Value *X, *Y, *Z;
- if (match(Op1, m_OneUse(m_UMin(m_Value(Y), m_Value(Z)))) &&
- (match(Op0, m_OneUse(m_c_Add(m_Specific(Y), m_Value(X)))) ||
- match(Op0, m_OneUse(m_c_Add(m_Specific(Z), m_Value(X)))))) {
- Value *USub =
- Builder.CreateIntrinsic(Intrinsic::usub_sat, I.getType(), {Y, Z});
- return BinaryOperator::CreateAdd(X, USub);
+ if (match(Op1, m_OneUse(m_UMin(m_Value(Y), m_Value(Z))))) {
+ if (match(Op0, m_OneUse(m_c_Add(m_Specific(Y), m_Value(X)))))
+ return BinaryOperator::CreateAdd(
+ X, Builder.CreateIntrinsic(Intrinsic::usub_sat, I.getType(),
+ {Y, Z}));
+ if (match(Op0, m_OneUse(m_c_Add(m_Specific(Z), m_Value(X)))))
+ return BinaryOperator::CreateAdd(
+ X, Builder.CreateIntrinsic(Intrinsic::usub_sat, I.getType(),
+ {Z, Y}));
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125352.428837.patch
Type: text/x-patch
Size: 2793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220512/0201c645/attachment.bin>
- Previous message: [PATCH] D125352: [InstCombine] fix sub(add(X,Y),umin(Y,Z)) --> add(X,usub.sat(Y,Z))
- Next message: [PATCH] D125352: [InstCombine] fix sub(add(X,Y),umin(Y,Z)) --> add(X,usub.sat(Y,Z))
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the llvm-commits
mailing list