[llvm] 5880526 - [InstSimplify] Add test for simplifying `({u,s}rem (mul {nuw,nsw} X, C1), C0)`; NFC
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 07:22:58 PDT 2024
Author: Noah Goldstein
Date: 2024-07-01T22:22:36+08:00
New Revision: 5880526b87e56802adf1533a5fe7bd4b9b402a07
URL: https://github.com/llvm/llvm-project/commit/5880526b87e56802adf1533a5fe7bd4b9b402a07
DIFF: https://github.com/llvm/llvm-project/commit/5880526b87e56802adf1533a5fe7bd4b9b402a07.diff
LOG: [InstSimplify] Add test for simplifying `({u,s}rem (mul {nuw,nsw} X, C1), C0)`; NFC
Added:
Modified:
llvm/test/Transforms/InstSimplify/rem.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstSimplify/rem.ll b/llvm/test/Transforms/InstSimplify/rem.ll
index a46db0342042f..ad9cb21a12cc9 100644
--- a/llvm/test/Transforms/InstSimplify/rem.ll
+++ b/llvm/test/Transforms/InstSimplify/rem.ll
@@ -265,7 +265,7 @@ define i32 @rem4() {
; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), !range [[RNG0:![0-9]+]]
; CHECK-NEXT: ret i32 [[CALL]]
;
- %call = call i32 @external(), !range !0
+ %call = call i32 @external() , !range !0
%urem = urem i32 %call, 3
ret i32 %urem
}
@@ -488,3 +488,58 @@ define i8 @urem_mul_sdiv(i8 %x, i8 %y) {
%mod = urem i8 %mul, %y
ret i8 %mod
}
+
+define <2 x i8> @simplfy_srem_of_mul(<2 x i8> %x) {
+; CHECK-LABEL: @simplfy_srem_of_mul(
+; CHECK-NEXT: [[MUL:%.*]] = mul nsw <2 x i8> [[X:%.*]], <i8 20, i8 10>
+; CHECK-NEXT: [[R:%.*]] = srem <2 x i8> [[MUL]], <i8 5, i8 5>
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %mul = mul nsw <2 x i8> %x, <i8 20, i8 10>
+ %r = srem <2 x i8> %mul, <i8 5, i8 5>
+ ret <2 x i8> %r
+}
+
+define <2 x i8> @simplfy_srem_of_mul_fail_bad_mod(<2 x i8> %x) {
+; CHECK-LABEL: @simplfy_srem_of_mul_fail_bad_mod(
+; CHECK-NEXT: [[MUL:%.*]] = mul nsw <2 x i8> [[X:%.*]], <i8 20, i8 11>
+; CHECK-NEXT: [[R:%.*]] = srem <2 x i8> [[MUL]], <i8 5, i8 5>
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %mul = mul nsw <2 x i8> %x, <i8 20, i8 11>
+ %r = srem <2 x i8> %mul, <i8 5, i8 5>
+ ret <2 x i8> %r
+}
+
+define i8 @simplfy_urem_of_mul(i8 %x) {
+; CHECK-LABEL: @simplfy_urem_of_mul(
+; CHECK-NEXT: [[MUL:%.*]] = mul nuw i8 [[X:%.*]], 30
+; CHECK-NEXT: [[R:%.*]] = urem i8 [[MUL]], 10
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %mul = mul nuw i8 %x, 30
+ %r = urem i8 %mul, 10
+ ret i8 %r
+}
+
+define i8 @simplfy_urem_of_mul_fail_bad_flag(i8 %x) {
+; CHECK-LABEL: @simplfy_urem_of_mul_fail_bad_flag(
+; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X:%.*]], 30
+; CHECK-NEXT: [[R:%.*]] = urem i8 [[MUL]], 10
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %mul = mul nsw i8 %x, 30
+ %r = urem i8 %mul, 10
+ ret i8 %r
+}
+
+define i8 @simplfy_urem_of_mul_fail_bad_mod(i8 %x) {
+; CHECK-LABEL: @simplfy_urem_of_mul_fail_bad_mod(
+; CHECK-NEXT: [[MUL:%.*]] = mul nuw i8 [[X:%.*]], 31
+; CHECK-NEXT: [[R:%.*]] = urem i8 [[MUL]], 10
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %mul = mul nuw i8 %x, 31
+ %r = urem i8 %mul, 10
+ ret i8 %r
+}
More information about the llvm-commits
mailing list