diff options
Diffstat (limited to 'llvm/test/Transforms/InstSimplify/div.ll')
| -rw-r--r-- | llvm/test/Transforms/InstSimplify/div.ll | 68 |
1 files changed, 68 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() { |

