[llvm] 4a8c0aa - [InstSimplify] add tests for udiv/urem with known bits; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 5 05:33:16 PST 2022
Author: Sanjay Patel
Date: 2022-01-05T08:33:04-05:00
New Revision: 4a8c0aa0942d51b76a458a305700acadc0e9622b
URL: https://github.com/llvm/llvm-project/commit/4a8c0aa0942d51b76a458a305700acadc0e9622b
DIFF: https://github.com/llvm/llvm-project/commit/4a8c0aa0942d51b76a458a305700acadc0e9622b.diff
LOG: [InstSimplify] add tests for udiv/urem with known bits; NFC
Added:
Modified:
llvm/test/Transforms/InstSimplify/div.ll
llvm/test/Transforms/InstSimplify/rem.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstSimplify/div.ll b/llvm/test/Transforms/InstSimplify/div.ll
index 721de127f61f4..c4e07d22e4a99 100644
--- a/llvm/test/Transforms/InstSimplify/div.ll
+++ b/llvm/test/Transforms/InstSimplify/div.ll
@@ -153,6 +153,32 @@ define i32 @not_udiv_constant_dividend_known_smaller_than_divisor(i32 %x) {
ret i32 %div
}
+define i8 @udiv_dividend_known_smaller_than_constant_divisor2(i1 %b) {
+; CHECK-LABEL: @udiv_dividend_known_smaller_than_constant_divisor2(
+; CHECK-NEXT: [[T0:%.*]] = zext i1 [[B:%.*]] to i8
+; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[T0]], 12
+; CHECK-NEXT: [[R:%.*]] = udiv i8 [[XOR]], 14
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %t0 = zext i1 %b to i8
+ %xor = xor i8 %t0, 12
+ %r = udiv i8 %xor, 14
+ ret i8 %r
+}
+
+define i8 @not_udiv_dividend_known_smaller_than_constant_divisor2(i1 %b) {
+; CHECK-LABEL: @not_udiv_dividend_known_smaller_than_constant_divisor2(
+; CHECK-NEXT: [[T0:%.*]] = zext i1 [[B:%.*]] to i8
+; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[T0]], 12
+; CHECK-NEXT: [[R:%.*]] = udiv i8 [[XOR]], 13
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %t0 = zext i1 %b to i8
+ %xor = xor i8 %t0, 12
+ %r = udiv i8 %xor, 13
+ ret i8 %r
+}
+
; This would require computing known bits on both x and y. Is it worth doing?
define i32 @udiv_dividend_known_smaller_than_divisor(i32 %x, i32 %y) {
@@ -185,7 +211,7 @@ declare i32 @external()
define i32 @div1() {
; CHECK-LABEL: @div1(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), [[RNG0:!range !.*]]
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), !range [[RNG0:![0-9]+]]
; CHECK-NEXT: ret i32 0
;
%call = call i32 @external(), !range !0
@@ -194,8 +220,9 @@ define i32 @div1() {
}
define i8 @sdiv_minusone_divisor() {
-; CHECK-LABEL: @sdiv_minusone_divisor
-; CHECK-NEXT: ret i8 poison
+; CHECK-LABEL: @sdiv_minusone_divisor(
+; CHECK-NEXT: ret i8 poison
+;
%v = sdiv i8 -128, -1
ret i8 %v
}
diff --git a/llvm/test/Transforms/InstSimplify/rem.ll b/llvm/test/Transforms/InstSimplify/rem.ll
index c42d6d855d44d..9b7852d50cc4b 100644
--- a/llvm/test/Transforms/InstSimplify/rem.ll
+++ b/llvm/test/Transforms/InstSimplify/rem.ll
@@ -183,6 +183,32 @@ define i32 @not_urem_dividend_known_smaller_than_constant_divisor(i32 %x) {
ret i32 %r
}
+define i8 @urem_dividend_known_smaller_than_constant_divisor2(i1 %b) {
+; CHECK-LABEL: @urem_dividend_known_smaller_than_constant_divisor2(
+; CHECK-NEXT: [[T0:%.*]] = zext i1 [[B:%.*]] to i8
+; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[T0]], 12
+; CHECK-NEXT: [[R:%.*]] = urem i8 [[XOR]], 14
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %t0 = zext i1 %b to i8
+ %xor = xor i8 %t0, 12
+ %r = urem i8 %xor, 14
+ ret i8 %r
+}
+
+define i8 @not_urem_dividend_known_smaller_than_constant_divisor2(i1 %b) {
+; CHECK-LABEL: @not_urem_dividend_known_smaller_than_constant_divisor2(
+; CHECK-NEXT: [[T0:%.*]] = zext i1 [[B:%.*]] to i8
+; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[T0]], 12
+; CHECK-NEXT: [[R:%.*]] = urem i8 [[XOR]], 13
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %t0 = zext i1 %b to i8
+ %xor = xor i8 %t0, 12
+ %r = urem i8 %xor, 13
+ ret i8 %r
+}
+
define i32 @urem_constant_dividend_known_smaller_than_divisor(i32 %x) {
; CHECK-LABEL: @urem_constant_dividend_known_smaller_than_divisor(
; CHECK-NEXT: ret i32 250
More information about the llvm-commits
mailing list