[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
Tue May 10 23:38:53 PDT 2022
Chenbing.Zheng created this revision.
Chenbing.Zheng added reviewers: nlopes, RKSimon, spatel.
Chenbing.Zheng added a project: LLVM.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Chenbing.Zheng requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan.
This patch fix bug left in D124503 <https://reviews.llvm.org/D124503>.
We should do
sub(add(X,Z),umin(Y,Z)) --> add(X,usub.sat(Z,Y))
instead of
sub(add(X,Z),umin(Y,Z)) --> add(X,usub.sat(Y,Z)).
I forget to update sub-minmax.ll in D124503 <https://reviews.llvm.org/D124503>,
[[TMP1:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[Y:%.*]], i8 [[Z:%.*]]) and
[[TMP1:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[Z:%.*]], i8 [[Y:%.*]]) can both pass llvm-lit test.
Repository:
rG LLVM Github Monorepo
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
@@ -715,9 +715,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: @sub_add_umin(
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.428568.patch
Type: text/x-patch
Size: 1880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220511/c3df209e/attachment.bin>
More information about the llvm-commits
mailing list