summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Transforms/InstSimplify/div.ll68
-rw-r--r--llvm/test/Transforms/InstSimplify/rem.ll69
2 files changed, 137 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstSimplify/div.ll b/llvm/test/Transforms/InstSimplify/div.ll
index f096719359d..be17746c24f 100644
--- a/llvm/test/Transforms/InstSimplify/div.ll
+++ b/llvm/test/Transforms/InstSimplify/div.ll
@@ -54,6 +54,74 @@ define <2 x i1> @udiv_bool_vec(<2 x i1> %x, <2 x i1> %y) {
ret <2 x i1> %div
}
+define i32 @udiv_quotient_known_smaller_than_constant_denom(i32 %x) {
+; CHECK-LABEL: @udiv_quotient_known_smaller_than_constant_denom(
+; CHECK-NEXT: ret i32 0
+;
+ %and = and i32 %x, 250
+ %div = udiv i32 %and, 251
+ ret i32 %div
+}
+
+define i32 @not_udiv_quotient_known_smaller_than_constant_denom(i32 %x) {
+; CHECK-LABEL: @not_udiv_quotient_known_smaller_than_constant_denom(
+; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 251
+; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[AND]], 251
+; CHECK-NEXT: ret i32 [[DIV]]
+;
+ %and = and i32 %x, 251
+ %div = udiv i32 %and, 251
+ ret i32 %div
+}
+
+define i32 @udiv_constant_quotient_known_smaller_than_denom(i32 %x) {
+; CHECK-LABEL: @udiv_constant_quotient_known_smaller_than_denom(
+; CHECK-NEXT: ret i32 0
+;
+ %or = or i32 %x, 251
+ %div = udiv i32 250, %or
+ ret i32 %div
+}
+
+define i32 @not_udiv_constant_quotient_known_smaller_than_denom(i32 %x) {
+; CHECK-LABEL: @not_udiv_constant_quotient_known_smaller_than_denom(
+; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 251
+; CHECK-NEXT: [[DIV:%.*]] = udiv i32 251, [[OR]]
+; CHECK-NEXT: ret i32 [[DIV]]
+;
+ %or = or i32 %x, 251
+ %div = udiv i32 251, %or
+ ret i32 %div
+}
+
+; This would require computing known bits on both x and y. Is it worth doing?
+
+define i32 @udiv_quotient_known_smaller_than_denom(i32 %x, i32 %y) {
+; CHECK-LABEL: @udiv_quotient_known_smaller_than_denom(
+; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 250
+; CHECK-NEXT: [[OR:%.*]] = or i32 %y, 251
+; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[AND]], [[OR]]
+; CHECK-NEXT: ret i32 [[DIV]]
+;
+ %and = and i32 %x, 250
+ %or = or i32 %y, 251
+ %div = udiv i32 %and, %or
+ ret i32 %div
+}
+
+define i32 @not_udiv_quotient_known_smaller_than_denom(i32 %x, i32 %y) {
+; CHECK-LABEL: @not_udiv_quotient_known_smaller_than_denom(
+; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 251
+; CHECK-NEXT: [[OR:%.*]] = or i32 %y, 251
+; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[AND]], [[OR]]
+; CHECK-NEXT: ret i32 [[DIV]]
+;
+ %and = and i32 %x, 251
+ %or = or i32 %y, 251
+ %div = udiv i32 %and, %or
+ ret i32 %div
+}
+
declare i32 @external()
define i32 @div1() {
diff --git a/llvm/test/Transforms/InstSimplify/rem.ll b/llvm/test/Transforms/InstSimplify/rem.ll
index b7f18f36b4b..05818043bc1 100644
--- a/llvm/test/Transforms/InstSimplify/rem.ll
+++ b/llvm/test/Transforms/InstSimplify/rem.ll
@@ -104,6 +104,75 @@ define i32 @rem3(i32 %x, i32 %n) {
ret i32 %mod1
}
+define i32 @urem_quotient_known_smaller_than_constant_denom(i32 %x) {
+; CHECK-LABEL: @urem_quotient_known_smaller_than_constant_denom(
+; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 250
+; CHECK-NEXT: ret i32 [[AND]]
+;
+ %and = and i32 %x, 250
+ %r = urem i32 %and, 251
+ ret i32 %r
+}
+
+define i32 @not_urem_quotient_known_smaller_than_constant_denom(i32 %x) {
+; CHECK-LABEL: @not_urem_quotient_known_smaller_than_constant_denom(
+; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 251
+; CHECK-NEXT: [[R:%.*]] = urem i32 [[AND]], 251
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %and = and i32 %x, 251
+ %r = urem i32 %and, 251
+ ret i32 %r
+}
+
+define i32 @urem_constant_quotient_known_smaller_than_denom(i32 %x) {
+; CHECK-LABEL: @urem_constant_quotient_known_smaller_than_denom(
+; CHECK-NEXT: ret i32 250
+;
+ %or = or i32 %x, 251
+ %r = urem i32 250, %or
+ ret i32 %r
+}
+
+define i32 @not_urem_constant_quotient_known_smaller_than_denom(i32 %x) {
+; CHECK-LABEL: @not_urem_constant_quotient_known_smaller_than_denom(
+; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 251
+; CHECK-NEXT: [[R:%.*]] = urem i32 251, [[OR]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %or = or i32 %x, 251
+ %r = urem i32 251, %or
+ ret i32 %r
+}
+
+; This would require computing known bits on both x and y. Is it worth doing?
+
+define i32 @urem_quotient_known_smaller_than_denom(i32 %x, i32 %y) {
+; CHECK-LABEL: @urem_quotient_known_smaller_than_denom(
+; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 250
+; CHECK-NEXT: [[OR:%.*]] = or i32 %y, 251
+; CHECK-NEXT: [[R:%.*]] = urem i32 [[AND]], [[OR]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %and = and i32 %x, 250
+ %or = or i32 %y, 251
+ %r = urem i32 %and, %or
+ ret i32 %r
+}
+
+define i32 @not_urem_quotient_known_smaller_than_denom(i32 %x, i32 %y) {
+; CHECK-LABEL: @not_urem_quotient_known_smaller_than_denom(
+; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 251
+; CHECK-NEXT: [[OR:%.*]] = or i32 %y, 251
+; CHECK-NEXT: [[R:%.*]] = urem i32 [[AND]], [[OR]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %and = and i32 %x, 251
+ %or = or i32 %y, 251
+ %r = urem i32 %and, %or
+ ret i32 %r
+}
+
declare i32 @external()
define i32 @rem4() {
OpenPOWER on IntegriCloud