[llvm] fa4b4f0 - [InstCombine] fold more constant remainder to select-of-constants remainder
Ben Shi via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 11 18:41:10 PDT 2022
Author: Liqin Weng
Date: 2022-04-12T09:40:56+08:00
New Revision: fa4b4f0fcb38e8f49e635ff486cb99d55daa07e0
URL: https://github.com/llvm/llvm-project/commit/fa4b4f0fcb38e8f49e635ff486cb99d55daa07e0
DIFF: https://github.com/llvm/llvm-project/commit/fa4b4f0fcb38e8f49e635ff486cb99d55daa07e0.diff
LOG: [InstCombine] fold more constant remainder to select-of-constants remainder
Reviewed By: xbolva00, spatel, Chenbing.Zheng
Differential Revision: https://reviews.llvm.org/D123486
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/rem.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 41717577c2266..ab3569830ba9b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1428,7 +1428,8 @@ Instruction *InstCombinerImpl::commonIRemTransforms(BinaryOperator &I) {
// TODO: Adapt simplifyDivRemOfSelectWithZeroOp to allow this and other folds.
if (match(Op0, m_ImmConstant()) &&
match(Op1, m_Select(m_Value(), m_ImmConstant(), m_ImmConstant()))) {
- if (Instruction *R = FoldOpIntoSelect(I, cast<SelectInst>(Op1)))
+ if (Instruction *R = FoldOpIntoSelect(I, cast<SelectInst>(Op1),
+ /*FoldWithMultiUse*/ true))
return R;
}
diff --git a/llvm/test/Transforms/InstCombine/rem.ll b/llvm/test/Transforms/InstCombine/rem.ll
index 63122363b7a81..b8c7294d17590 100644
--- a/llvm/test/Transforms/InstCombine/rem.ll
+++ b/llvm/test/Transforms/InstCombine/rem.ll
@@ -742,8 +742,8 @@ define i1 @test28(i32 %A) {
define i1 @positive_and_odd_eq(i32 %A) {
; CHECK-LABEL: @positive_and_odd_eq(
-; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -2147483647
-; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[B]], 1
+; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2147483647
+; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[TMP1]], 1
; CHECK-NEXT: ret i1 [[C]]
;
%B = srem i32 %A, 2
@@ -764,8 +764,8 @@ define i1 @negative_and_odd_eq(i32 %A) {
define i1 @positive_and_odd_ne(i32 %A) {
; CHECK-LABEL: @positive_and_odd_ne(
-; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -2147483647
-; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[B]], 1
+; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2147483647
+; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[TMP1]], 1
; CHECK-NEXT: ret i1 [[C]]
;
%B = srem i32 %A, 2
@@ -807,13 +807,11 @@ define i32 @srem_constant_dividend_select_of_constants_divisor(i1 %b) {
ret i32 %r
}
-; TODO: srem should still be replaced by select.
-
define i32 @srem_constant_dividend_select_of_constants_divisor_use(i1 %b) {
; CHECK-LABEL: @srem_constant_dividend_select_of_constants_divisor_use(
; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 -3
; CHECK-NEXT: call void @use(i32 [[S]])
-; CHECK-NEXT: [[R:%.*]] = srem i32 42, [[S]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[B]], i32 6, i32 0
; CHECK-NEXT: ret i32 [[R]]
;
%s = select i1 %b, i32 12, i32 -3
@@ -915,13 +913,11 @@ define i32 @urem_constant_dividend_select_of_constants_divisor(i1 %b) {
ret i32 %r
}
-; TODO: urem should still be replaced by select.
-
define i32 @urem_constant_dividend_select_of_constants_divisor_use(i1 %b) {
; CHECK-LABEL: @urem_constant_dividend_select_of_constants_divisor_use(
; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 -3
; CHECK-NEXT: call void @use(i32 [[S]])
-; CHECK-NEXT: [[R:%.*]] = urem i32 42, [[S]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[B]], i32 6, i32 42
; CHECK-NEXT: ret i32 [[R]]
;
%s = select i1 %b, i32 12, i32 -3
More information about the llvm-commits
mailing list