[llvm] 4665f3c - Revert "[InstCombine] Add support for max(a,b) + min(a,b) => a + b."
Serguei Katkov via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 6 21:16:07 PDT 2023
Author: Serguei Katkov
Date: 2023-04-07T11:14:28+07:00
New Revision: 4665f3c8387edada6ba14eb2eac3240271ae74ec
URL: https://github.com/llvm/llvm-project/commit/4665f3c8387edada6ba14eb2eac3240271ae74ec
DIFF: https://github.com/llvm/llvm-project/commit/4665f3c8387edada6ba14eb2eac3240271ae74ec.diff
LOG: Revert "[InstCombine] Add support for max(a,b) + min(a,b) => a + b."
Revert commit due to failure on buildbot:
error: 'match_combine_or' may not intend to support class template argument deduction
This reverts commit b86a06ef284f2637bef89bf5bb20157a8b195568.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/add-min-max.ll
llvm/test/Transforms/InstCombine/mul-min-max.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 7dd9fc45f10d..2c2b767b2ced 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1554,14 +1554,6 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
if (Instruction *Ashr = foldAddToAshr(I))
return Ashr;
- // min(A, B) + max(A, B) => A + B.
- if (match(&I,
- match_combine_or(m_c_Add(m_SMax(m_Value(A), m_Value(B)),
- m_c_SMin(m_Deferred(A), m_Deferred(B))),
- m_c_Add(m_UMax(m_Value(A), m_Value(B)),
- m_c_UMin(m_Deferred(A), m_Deferred(B))))))
- return BinaryOperator::CreateWithCopiedFlags(Instruction::Add, A, B, &I);
-
// TODO(jingyue): Consider willNotOverflowSignedAdd and
// willNotOverflowUnsignedAdd to reduce the number of invocations of
// computeKnownBits.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index a3baff33739d..5768f71265cc 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -471,14 +471,6 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
if (Instruction *Ext = narrowMathIfNoOverflow(I))
return Ext;
- // min(X, Y) * max(X, Y) => X * Y.
- if (match(&I,
- match_combine_or(m_c_Mul(m_SMax(m_Value(X), m_Value(Y)),
- m_c_SMin(m_Deferred(X), m_Deferred(Y))),
- m_c_Mul(m_UMax(m_Value(X), m_Value(Y)),
- m_c_UMin(m_Deferred(X), m_Deferred(Y))))))
- return BinaryOperator::CreateWithCopiedFlags(Instruction::Mul, X, Y, &I);
-
bool Changed = false;
if (!HasNSW && willNotOverflowSignedMul(Op0, Op1, I)) {
Changed = true;
diff --git a/llvm/test/Transforms/InstCombine/add-min-max.ll b/llvm/test/Transforms/InstCombine/add-min-max.ll
index 2117a55e2a49..d077d18f6ee9 100644
--- a/llvm/test/Transforms/InstCombine/add-min-max.ll
+++ b/llvm/test/Transforms/InstCombine/add-min-max.ll
@@ -9,7 +9,9 @@ declare i32 @llvm.umin.i32(i32 %a, i32 %b)
define i32 @uadd_min_max(i32 %a, i32 %b) {
; CHECK-LABEL: @uadd_min_max(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[A:%.*]], i32 [[B:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = add i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -22,7 +24,9 @@ entry:
define i32 @uadd_min_max_comm(i32 %a, i32 %b) {
; CHECK-LABEL: @uadd_min_max_comm(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = add i32 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[B:%.*]], i32 [[A:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = add i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -35,7 +39,9 @@ entry:
define i32 @uadd_min_max_nuw_nsw(i32 %a, i32 %b) {
; CHECK-LABEL: @uadd_min_max_nuw_nsw(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = add nuw nsw i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[A:%.*]], i32 [[B:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = add nuw nsw i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -48,7 +54,9 @@ entry:
define i32 @sadd_min_max(i32 %a, i32 %b) {
; CHECK-LABEL: @sadd_min_max(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.smax.i32(i32 [[A:%.*]], i32 [[B:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = add i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -61,7 +69,9 @@ entry:
define i32 @sadd_min_max_comm(i32 %a, i32 %b) {
; CHECK-LABEL: @sadd_min_max_comm(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = add i32 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.smax.i32(i32 [[B:%.*]], i32 [[A:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = add i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -74,7 +84,9 @@ entry:
define i32 @sadd_min_max_nuw_nsw(i32 %a, i32 %b) {
; CHECK-LABEL: @sadd_min_max_nuw_nsw(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = add nuw nsw i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.smax.i32(i32 [[A:%.*]], i32 [[B:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = add nuw nsw i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
diff --git a/llvm/test/Transforms/InstCombine/mul-min-max.ll b/llvm/test/Transforms/InstCombine/mul-min-max.ll
index fce6b9576dc3..e6808ffa18a5 100644
--- a/llvm/test/Transforms/InstCombine/mul-min-max.ll
+++ b/llvm/test/Transforms/InstCombine/mul-min-max.ll
@@ -9,7 +9,9 @@ declare i32 @llvm.umin.i32(i32 %a, i32 %b)
define i32 @umul_min_max(i32 %a, i32 %b) {
; CHECK-LABEL: @umul_min_max(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = mul i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[A:%.*]], i32 [[B:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = mul i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -22,7 +24,9 @@ entry:
define i32 @umul_min_max_comm(i32 %a, i32 %b) {
; CHECK-LABEL: @umul_min_max_comm(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = mul i32 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[B:%.*]], i32 [[A:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = mul i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -35,7 +39,9 @@ entry:
define i32 @umul_min_max_nuw_nsw(i32 %a, i32 %b) {
; CHECK-LABEL: @umul_min_max_nuw_nsw(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = mul nuw nsw i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[A:%.*]], i32 [[B:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = mul nuw nsw i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -48,7 +54,9 @@ entry:
define i32 @smul_min_max(i32 %a, i32 %b) {
; CHECK-LABEL: @smul_min_max(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = mul i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.smax.i32(i32 [[A:%.*]], i32 [[B:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = mul i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -61,7 +69,9 @@ entry:
define i32 @smul_min_max_comm(i32 %a, i32 %b) {
; CHECK-LABEL: @smul_min_max_comm(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = mul i32 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.smax.i32(i32 [[B:%.*]], i32 [[A:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = mul i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
@@ -74,7 +84,9 @@ entry:
define i32 @smul_min_max_nuw_nsw(i32 %a, i32 %b) {
; CHECK-LABEL: @smul_min_max_nuw_nsw(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[RES:%.*]] = mul nuw nsw i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.smax.i32(i32 [[A:%.*]], i32 [[B:%.*]])
+; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[A]], i32 [[B]])
+; CHECK-NEXT: [[RES:%.*]] = mul nuw nsw i32 [[MIN]], [[MAX]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
More information about the llvm-commits
mailing list