From: Sanjay Patel Date: Mon, 27 Jun 2016 20:28:59 +0000 (+0000) Subject: add tests for PR28153 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87796a309600bc498a1b737c59fd936d1c9cf65a;p=llvm add tests for PR28153 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273936 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Transforms/InstCombine/div.ll b/test/Transforms/InstCombine/div.ll index 2b7c907f177..4ad7005da20 100644 --- a/test/Transforms/InstCombine/div.ll +++ b/test/Transforms/InstCombine/div.ll @@ -408,3 +408,79 @@ lor.end: ; preds = %lor.rhs, %entry %div = sdiv i32 %t.0, 2 ret i32 %div } + +; FIXME: +; We can perform the division in the smaller type. + +define i32 @shrink(i8 %x) { +; CHECK-LABEL: @shrink( +; CHECK-NEXT: [[CONV:%.*]] = sext i8 %x to i32 +; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[CONV]], 127 +; CHECK-NEXT: ret i32 [[DIV]] +; + %conv = sext i8 %x to i32 + %div = sdiv i32 %conv, 127 + ret i32 %div +} + +; Division in the smaller type can lead to more optimizations. + +define i32 @zap(i8 %x) { +; CHECK-LABEL: @zap( +; CHECK-NEXT: [[CONV:%.*]] = sext i8 %x to i32 +; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[CONV]], -128 +; CHECK-NEXT: ret i32 [[DIV]] +; + %conv = sext i8 %x to i32 + %div = sdiv i32 %conv, -128 + ret i32 %div +} + +; Splat constant divisors should get the same folds. + +define <3 x i32> @shrink_vec(<3 x i8> %x) { +; CHECK-LABEL: @shrink_vec( +; CHECK-NEXT: [[CONV:%.*]] = sext <3 x i8> %x to <3 x i32> +; CHECK-NEXT: [[DIV:%.*]] = sdiv <3 x i32> [[CONV]], +; CHECK-NEXT: ret <3 x i32> [[DIV]] +; + %conv = sext <3 x i8> %x to <3 x i32> + %div = sdiv <3 x i32> %conv, + ret <3 x i32> %div +} + +define <2 x i32> @zap_vec(<2 x i8> %x) { +; CHECK-LABEL: @zap_vec( +; CHECK-NEXT: [[CONV:%.*]] = sext <2 x i8> %x to <2 x i32> +; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[CONV]], +; CHECK-NEXT: ret <2 x i32> [[DIV]] +; + %conv = sext <2 x i8> %x to <2 x i32> + %div = sdiv <2 x i32> %conv, + ret <2 x i32> %div +} + +; But we can't do this if the signed constant won't fit in the original type. + +define i32 @shrink_no(i8 %x) { +; CHECK-LABEL: @shrink_no( +; CHECK-NEXT: [[CONV:%.*]] = sext i8 %x to i32 +; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[CONV]], 128 +; CHECK-NEXT: ret i32 [[DIV]] +; + %conv = sext i8 %x to i32 + %div = sdiv i32 %conv, 128 + ret i32 %div +} + +define i32 @shrink_no2(i8 %x) { +; CHECK-LABEL: @shrink_no2( +; CHECK-NEXT: [[CONV:%.*]] = sext i8 %x to i32 +; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[CONV]], -129 +; CHECK-NEXT: ret i32 [[DIV]] +; + %conv = sext i8 %x to i32 + %div = sdiv i32 %conv, -129 + ret i32 %div +} +