[PATCH] D101184: [InstCombine] X - usub.sat(X, Y) => umin(X, Y)

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 23 10:27:36 PDT 2021


xbolva00 created this revision.
xbolva00 added reviewers: nikic, spatel.
Herald added a subscriber: hiraditya.
xbolva00 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Pattern regressed in LLVM 9 with the introduction of usub.sat.

Fixes https://bugs.llvm.org/show_bug.cgi?id=42178#c2


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101184

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/test/Transforms/InstCombine/saturating-add-sub.ll


Index: llvm/test/Transforms/InstCombine/saturating-add-sub.ll
===================================================================
--- llvm/test/Transforms/InstCombine/saturating-add-sub.ll
+++ llvm/test/Transforms/InstCombine/saturating-add-sub.ll
@@ -1098,9 +1098,8 @@
 
 define i8 @test_scalar_usub_sub(i8 %a, i8 %b) {
 ; CHECK-LABEL: @test_scalar_usub_sub(
-; CHECK-NEXT:    [[SAT:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[A:%.*]], i8 [[B:%.*]])
-; CHECK-NEXT:    [[RES:%.*]] = sub i8 [[A]], [[SAT]]
-; CHECK-NEXT:    ret i8 [[RES]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call i8 @llvm.umin.i8(i8 [[A:%.*]], i8 [[B:%.*]])
+; CHECK-NEXT:    ret i8 [[TMP1]]
 ;
   %sat = call i8 @llvm.usub.sat.i8(i8 %a, i8 %b)
   %res = sub i8 %a, %sat
@@ -1122,9 +1121,8 @@
 
 define <2 x i8> @test_vector_usub_sub(<2 x i8> %a, <2 x i8> %b) {
 ; CHECK-LABEL: @test_vector_usub_sub(
-; CHECK-NEXT:    [[SAT:%.*]] = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> [[A:%.*]], <2 x i8> [[B:%.*]])
-; CHECK-NEXT:    [[RES:%.*]] = sub <2 x i8> [[A]], [[SAT]]
-; CHECK-NEXT:    ret <2 x i8> [[RES]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call <2 x i8> @llvm.umin.v2i8(<2 x i8> [[A:%.*]], <2 x i8> [[B:%.*]])
+; CHECK-NEXT:    ret <2 x i8> [[TMP1]]
 ;
   %sat = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> %a, <2 x i8> %b)
   %res = sub <2 x i8> %a, %sat
Index: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -2098,6 +2098,12 @@
           canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(I))
     return V;
 
+  // X - usub.sat(X, Y) => umin(X, Y)
+  if (match(Op1, m_OneUse(m_Intrinsic<Intrinsic::usub_sat>(m_Specific(Op0),
+                                                           m_Value(Y)))))
+    return replaceInstUsesWith(
+        I, Builder.CreateIntrinsic(Intrinsic::umin, {I.getType()}, {Op0, Y}));
+
   return TryToNarrowDeduceFlags();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101184.340104.patch
Type: text/x-patch
Size: 2022 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210423/e95011c6/attachment.bin>


More information about the llvm-commits mailing list