summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-06-27 22:27:11 +0000
committerSanjay Patel <spatel@rotateright.com>2016-06-27 22:27:11 +0000
commit59ed2ffca38f01b326459d366d1b131ec45eb483 (patch)
tree480c5bebdf739530d2b2e42e14e0aa19592092b7 /llvm/test
parenta657f875a91b652adb3a373265db2745c1e7680d (diff)
downloadbcm5719-llvm-59ed2ffca38f01b326459d366d1b131ec45eb483.tar.gz
bcm5719-llvm-59ed2ffca38f01b326459d366d1b131ec45eb483.zip
[InstCombine] shrink type of sdiv if dividend is sexted and constant divisor is small enough (PR28153)
This should fix PR28153: https://llvm.org/bugs/show_bug.cgi?id=28153 Differential Revision: http://reviews.llvm.org/D21769 llvm-svn: 273951
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Transforms/InstCombine/div.ll30
1 files changed, 21 insertions, 9 deletions
diff --git a/llvm/test/Transforms/InstCombine/div.ll b/llvm/test/Transforms/InstCombine/div.ll
index 4ad7005da20..a19cdefa31f 100644
--- a/llvm/test/Transforms/InstCombine/div.ll
+++ b/llvm/test/Transforms/InstCombine/div.ll
@@ -409,13 +409,12 @@ lor.end: ; preds = %lor.rhs, %entry
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: [[TMP1:%.*]] = sdiv i8 %x, 127
+; CHECK-NEXT: [[DIV:%.*]] = sext i8 [[TMP1]] to i32
; CHECK-NEXT: ret i32 [[DIV]]
;
%conv = sext i8 %x to i32
@@ -427,8 +426,8 @@ define i32 @shrink(i8 %x) {
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: [[TMP1:%.*]] = icmp eq i8 %x, -128
+; CHECK-NEXT: [[DIV:%.*]] = zext i1 [[TMP1]] to i32
; CHECK-NEXT: ret i32 [[DIV]]
;
%conv = sext i8 %x to i32
@@ -440,8 +439,8 @@ define i32 @zap(i8 %x) {
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]], <i32 127, i32 127, i32 127>
+; CHECK-NEXT: [[TMP1:%.*]] = sdiv <3 x i8> %x, <i8 127, i8 127, i8 127>
+; CHECK-NEXT: [[DIV:%.*]] = sext <3 x i8> [[TMP1]] to <3 x i32>
; CHECK-NEXT: ret <3 x i32> [[DIV]]
;
%conv = sext <3 x i8> %x to <3 x i32>
@@ -451,8 +450,8 @@ define <3 x i32> @shrink_vec(<3 x i8> %x) {
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]], <i32 -128, i32 -128>
+; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> %x, <i8 -128, i8 -128>
+; CHECK-NEXT: [[DIV:%.*]] = zext <2 x i1> [[TMP1]] to <2 x i32>
; CHECK-NEXT: ret <2 x i32> [[DIV]]
;
%conv = sext <2 x i8> %x to <2 x i32>
@@ -484,3 +483,16 @@ define i32 @shrink_no2(i8 %x) {
ret i32 %div
}
+; 17 bits are needed to represent 65535 as a signed value, so this shouldn't fold.
+
+define i32 @shrink_no3(i16 %x) {
+; CHECK-LABEL: @shrink_no3(
+; CHECK-NEXT: [[CONV:%.*]] = sext i16 %x to i32
+; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[CONV]], 65535
+; CHECK-NEXT: ret i32 [[DIV]]
+;
+ %conv = sext i16 %x to i32
+ %div = sdiv i32 %conv, 65535
+ ret i32 %div
+}
+
OpenPOWER on IntegriCloud