summaryrefslogtreecommitdiffstats
path: root/test/Transforms/InstCombine/cast.ll
diff options
context:
space:
mode:
Diffstat (limited to 'test/Transforms/InstCombine/cast.ll')
-rw-r--r--test/Transforms/InstCombine/cast.ll99
1 files changed, 92 insertions, 7 deletions
diff --git a/test/Transforms/InstCombine/cast.ll b/test/Transforms/InstCombine/cast.ll
index 0cbfbb0..578b16d 100644
--- a/test/Transforms/InstCombine/cast.ll
+++ b/test/Transforms/InstCombine/cast.ll
@@ -354,6 +354,24 @@ define i32* @test41(i32* %tmp1) {
; CHECK: ret i32* %tmp1
}
+define i32 addrspace(1)* @test41_addrspacecast_smaller(i32* %tmp1) {
+ %tmp64 = addrspacecast i32* %tmp1 to { i32 } addrspace(1)*
+ %tmp65 = getelementptr { i32 } addrspace(1)* %tmp64, i32 0, i32 0
+ ret i32 addrspace(1)* %tmp65
+; CHECK-LABEL: @test41_addrspacecast_smaller(
+; CHECK: addrspacecast i32* %tmp1 to i32 addrspace(1)*
+; CHECK-NEXT: ret i32 addrspace(1)*
+}
+
+define i32* @test41_addrspacecast_larger(i32 addrspace(1)* %tmp1) {
+ %tmp64 = addrspacecast i32 addrspace(1)* %tmp1 to { i32 }*
+ %tmp65 = getelementptr { i32 }* %tmp64, i32 0, i32 0
+ ret i32* %tmp65
+; CHECK-LABEL: @test41_addrspacecast_larger(
+; CHECK: addrspacecast i32 addrspace(1)* %tmp1 to i32*
+; CHECK-NEXT: ret i32*
+}
+
define i32 @test42(i32 %X) {
%Y = trunc i32 %X to i8 ; <i8> [#uses=1]
%Z = zext i8 %Y to i32 ; <i32> [#uses=1]
@@ -792,7 +810,7 @@ define double @test71(double *%p, i64 %i) {
define double @test72(double *%p, i32 %i) {
; CHECK-LABEL: @test72(
- %so = mul nsw i32 %i, 8
+ %so = shl nsw i32 %i, 3
%o = sext i32 %so to i64
; CHECK-NEXT: sext i32 %i to i64
%q = bitcast double* %p to i8*
@@ -807,7 +825,7 @@ define double @test72(double *%p, i32 %i) {
define double @test73(double *%p, i128 %i) {
; CHECK-LABEL: @test73(
- %lo = mul nsw i128 %i, 8
+ %lo = shl nsw i128 %i, 3
%o = trunc i128 %lo to i64
; CHECK-NEXT: trunc i128 %i to i64
%q = bitcast double* %p to i8*
@@ -919,7 +937,7 @@ define %s @test79(%s *%p, i64 %i, i32 %j) {
define double @test80([100 x double]* %p, i32 %i) {
; CHECK-LABEL: @test80(
- %tmp = mul nsw i32 %i, 8
+ %tmp = shl nsw i32 %i, 3
; CHECK-NEXT: sext i32 %i to i64
%q = bitcast [100 x double]* %p to i8*
%pp = getelementptr i8* %q, i32 %tmp
@@ -936,7 +954,7 @@ define double @test80_addrspacecast([100 x double] addrspace(1)* %p, i32 %i) {
; CHECK-NEXT: getelementptr [100 x double] addrspace(1)* %p
; CHECK-NEXT: load double addrspace(1)*
; CHECK-NEXT: ret double
- %tmp = mul nsw i32 %i, 8
+ %tmp = shl nsw i32 %i, 3
%q = addrspacecast [100 x double] addrspace(1)* %p to i8 addrspace(2)*
%pp = getelementptr i8 addrspace(2)* %q, i32 %tmp
%r = addrspacecast i8 addrspace(2)* %pp to double addrspace(1)*
@@ -950,7 +968,7 @@ define double @test80_addrspacecast_2([100 x double] addrspace(1)* %p, i32 %i) {
; CHECK-NEXT: addrspacecast double addrspace(1)*
; CHECK-NEXT: load double addrspace(3)*
; CHECK-NEXT: ret double
- %tmp = mul nsw i32 %i, 8
+ %tmp = shl nsw i32 %i, 3
%q = addrspacecast [100 x double] addrspace(1)* %p to i8 addrspace(2)*
%pp = getelementptr i8 addrspace(2)* %q, i32 %tmp
%r = addrspacecast i8 addrspace(2)* %pp to double addrspace(3)*
@@ -960,7 +978,7 @@ define double @test80_addrspacecast_2([100 x double] addrspace(1)* %p, i32 %i) {
define double @test80_as1([100 x double] addrspace(1)* %p, i16 %i) {
; CHECK-LABEL: @test80_as1(
- %tmp = mul nsw i16 %i, 8
+ %tmp = shl nsw i16 %i, 3
; CHECK-NEXT: sext i16 %i to i32
%q = bitcast [100 x double] addrspace(1)* %p to i8 addrspace(1)*
%pp = getelementptr i8 addrspace(1)* %q, i16 %tmp
@@ -1004,7 +1022,74 @@ define i64 @test83(i16 %a, i64 %k) {
ret i64 %sh_prom1
; CHECK-LABEL: @test83(
-; CHECK: %sub = add nsw i64 %k, 4294967295
+; CHECK: %sub = add i64 %k, 4294967295
; CHECK: %sh_prom = trunc i64 %sub to i32
; CHECK: %shl = shl i32 %conv, %sh_prom
}
+
+define i8 @test84(i32 %a) {
+ %add = add nsw i32 %a, -16777216
+ %shr = lshr exact i32 %add, 23
+ %trunc = trunc i32 %shr to i8
+ ret i8 %trunc
+
+; CHECK-LABEL: @test84(
+; CHECK: [[ADD:%.*]] = add i32 %a, 2130706432
+; CHECK: [[SHR:%.*]] = lshr exact i32 [[ADD]], 23
+; CHECK: [[CST:%.*]] = trunc i32 [[SHR]] to i8
+}
+
+define i8 @test85(i32 %a) {
+ %add = add nuw i32 %a, -16777216
+ %shr = lshr exact i32 %add, 23
+ %trunc = trunc i32 %shr to i8
+ ret i8 %trunc
+
+; CHECK-LABEL: @test85(
+; CHECK: [[ADD:%.*]] = add i32 %a, 2130706432
+; CHECK: [[SHR:%.*]] = lshr exact i32 [[ADD]], 23
+; CHECK: [[CST:%.*]] = trunc i32 [[SHR]] to i8
+}
+
+; Overflow on a float to int or int to float conversion is undefined (PR21130).
+
+define i8 @overflow_fptosi() {
+ %i = fptosi double 1.56e+02 to i8
+ ret i8 %i
+; CHECK-LABEL: @overflow_fptosi(
+; CHECK-NEXT: ret i8 undef
+}
+
+define i8 @overflow_fptoui() {
+ %i = fptoui double 2.56e+02 to i8
+ ret i8 %i
+; CHECK-LABEL: @overflow_fptoui(
+; CHECK-NEXT: ret i8 undef
+}
+
+; The maximum float is approximately 2 ** 128 which is 3.4E38.
+; The constant below is 4E38. Use a 130 bit integer to hold that
+; number; 129-bits for the value + 1 bit for the sign.
+define float @overflow_uitofp() {
+ %i = uitofp i130 400000000000000000000000000000000000000 to float
+ ret float %i
+; CHECK-LABEL: @overflow_uitofp(
+; CHECK-NEXT: ret float undef
+}
+
+define float @overflow_sitofp() {
+ %i = sitofp i130 400000000000000000000000000000000000000 to float
+ ret float %i
+; CHECK-LABEL: @overflow_sitofp(
+; CHECK-NEXT: ret float undef
+}
+
+define i32 @PR21388(i32* %v) {
+ %icmp = icmp slt i32* %v, null
+ %sext = sext i1 %icmp to i32
+ ret i32 %sext
+; CHECK-LABEL: @PR21388(
+; CHECK-NEXT: %[[icmp:.*]] = icmp slt i32* %v, null
+; CHECK-NEXT: %[[sext:.*]] = sext i1 %[[icmp]] to i32
+; CHECK-NEXT: ret i32 %[[sext]]
+}