X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=test%2FTransforms%2FInstCombine%2Fcast.ll;h=578b16d981135bd5a3b8f0530a6636de9f26a058;hp=899ffddd5bca60cecd2ff8ad213fea38931d58ee;hb=fe58be3733715dd30807e9aaa31500be456ecf53;hpb=bbc7016c60bfe319f4d3bbc525547596e85c9aad diff --git a/test/Transforms/InstCombine/cast.ll b/test/Transforms/InstCombine/cast.ll index 899ffddd5bc..578b16d9811 100644 --- a/test/Transforms/InstCombine/cast.ll +++ b/test/Transforms/InstCombine/cast.ll @@ -1,6 +1,6 @@ ; Tests to make sure elimination of casts is working correctly ; RUN: opt < %s -instcombine -S | FileCheck %s -target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n8:16:32:64" +target datalayout = "E-p:64:64:64-p1:32:32:32-p2:64:64:64-p3:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n8:16:32:64" @inbuf = external global [32832 x i8] ; <[32832 x i8]*> [#uses=1] @@ -326,7 +326,7 @@ define i16 @test39(i16 %a) { %tmp.upgrd.32 = or i32 %tmp21, %tmp5 %tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16 ret i16 %tmp.upgrd.3 -; CHECK: @test39 +; CHECK-LABEL: @test39( ; CHECK: %tmp.upgrd.32 = call i16 @llvm.bswap.i16(i16 %a) ; CHECK: ret i16 %tmp.upgrd.32 } @@ -338,7 +338,7 @@ define i16 @test40(i16 %a) { %tmp.upgrd.32 = or i32 %tmp21, %tmp5 %tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16 ret i16 %tmp.upgrd.3 -; CHECK: @test40 +; CHECK-LABEL: @test40( ; CHECK: %tmp21 = lshr i16 %a, 9 ; CHECK: %tmp5 = shl i16 %a, 8 ; CHECK: %tmp.upgrd.32 = or i16 %tmp21, %tmp5 @@ -350,15 +350,33 @@ define i32* @test41(i32* %tmp1) { %tmp64 = bitcast i32* %tmp1 to { i32 }* %tmp65 = getelementptr { i32 }* %tmp64, i32 0, i32 0 ret i32* %tmp65 -; CHECK: @test41 +; CHECK-LABEL: @test41( ; 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 ; [#uses=1] %Z = zext i8 %Y to i32 ; [#uses=1] ret i32 %Z -; CHECK: @test42 +; CHECK-LABEL: @test42( ; CHECK: %Z = and i32 %X, 255 } @@ -368,9 +386,9 @@ define zeroext i64 @test43(i8 zeroext %on_off) nounwind readonly { %B = add i32 %A, -1 %C = sext i32 %B to i64 ret i64 %C ;; Should be (add (zext i8 -> i64), -1) -; CHECK: @test43 +; CHECK-LABEL: @test43( ; CHECK-NEXT: %A = zext i8 %on_off to i64 -; CHECK-NEXT: %B = add i64 %A, -1 +; CHECK-NEXT: %B = add nsw i64 %A, -1 ; CHECK-NEXT: ret i64 %B } @@ -379,7 +397,7 @@ define i64 @test44(i8 %T) { %B = or i16 %A, 1234 %C = zext i16 %B to i64 ret i64 %C -; CHECK: @test44 +; CHECK-LABEL: @test44( ; CHECK-NEXT: %A = zext i8 %T to i64 ; CHECK-NEXT: %B = or i64 %A, 1234 ; CHECK-NEXT: ret i64 %B @@ -391,7 +409,7 @@ define i64 @test45(i8 %A, i64 %Q) { %C = or i32 %B, %D %E = zext i32 %C to i64 ret i64 %E -; CHECK: @test45 +; CHECK-LABEL: @test45( ; CHECK-NEXT: %B = sext i8 %A to i64 ; CHECK-NEXT: %C = or i64 %B, %Q ; CHECK-NEXT: %E = and i64 %C, 4294967295 @@ -405,7 +423,7 @@ define i64 @test46(i64 %A) { %D = shl i32 %C, 8 %E = zext i32 %D to i64 ret i64 %E -; CHECK: @test46 +; CHECK-LABEL: @test46( ; CHECK-NEXT: %C = shl i64 %A, 8 ; CHECK-NEXT: %D = and i64 %C, 10752 ; CHECK-NEXT: ret i64 %D @@ -416,7 +434,7 @@ define i64 @test47(i8 %A) { %C = or i32 %B, 42 %E = zext i32 %C to i64 ret i64 %E -; CHECK: @test47 +; CHECK-LABEL: @test47( ; CHECK-NEXT: %B = sext i8 %A to i64 ; CHECK-NEXT: %C = and i64 %B, 4294967253 ; CHECK-NEXT: %E = or i64 %C, 42 @@ -430,7 +448,7 @@ define i64 @test48(i8 %A, i8 %a) { %D = or i32 %C, %b %E = zext i32 %D to i64 ret i64 %E -; CHECK: @test48 +; CHECK-LABEL: @test48( ; CHECK-NEXT: %b = zext i8 %a to i64 ; CHECK-NEXT: %B = zext i8 %A to i64 ; CHECK-NEXT: %C = shl nuw nsw i64 %B, 8 @@ -443,7 +461,7 @@ define i64 @test49(i64 %A) { %C = or i32 %B, 1 %D = sext i32 %C to i64 ret i64 %D -; CHECK: @test49 +; CHECK-LABEL: @test49( ; CHECK-NEXT: %C = shl i64 %A, 32 ; CHECK-NEXT: ashr exact i64 %C, 32 ; CHECK-NEXT: %D = or i64 {{.*}}, 1 @@ -456,7 +474,7 @@ define i64 @test50(i64 %A) { %D = add i32 %B, -1 %E = sext i32 %D to i64 ret i64 %E -; CHECK: @test50 +; CHECK-LABEL: @test50( ; lshr+shl will be handled by DAGCombine. ; CHECK-NEXT: lshr i64 %A, 2 ; CHECK-NEXT: shl i64 %a, 32 @@ -472,15 +490,13 @@ define i64 @test51(i64 %A, i1 %cond) { %E = select i1 %cond, i32 %C, i32 %D %F = sext i32 %E to i64 ret i64 %F -; CHECK: @test51 - -; FIXME: disabled, see PR5997 -; HECK-NEXT: %C = and i64 %A, 4294967294 -; HECK-NEXT: %D = or i64 %A, 1 -; HECK-NEXT: %E = select i1 %cond, i64 %C, i64 %D -; HECK-NEXT: %sext = shl i64 %E, 32 -; HECK-NEXT: %F = ashr i64 %sext, 32 -; HECK-NEXT: ret i64 %F +; CHECK-LABEL: @test51( +; CHECK-NEXT: %C = and i64 %A, 4294967294 +; CHECK-NEXT: %D = or i64 %A, 1 +; CHECK-NEXT: %E = select i1 %cond, i64 %C, i64 %D +; CHECK-NEXT: %sext = shl i64 %E, 32 +; CHECK-NEXT: %F = ashr exact i64 %sext, 32 +; CHECK-NEXT: ret i64 %F } define i32 @test52(i64 %A) { @@ -489,7 +505,7 @@ define i32 @test52(i64 %A) { %D = and i16 %C, -25350 %E = zext i16 %D to i32 ret i32 %E -; CHECK: @test52 +; CHECK-LABEL: @test52( ; CHECK-NEXT: %B = trunc i64 %A to i32 ; CHECK-NEXT: %C = and i32 %B, 7224 ; CHECK-NEXT: %D = or i32 %C, 32962 @@ -502,7 +518,7 @@ define i64 @test53(i32 %A) { %D = and i16 %C, -25350 %E = zext i16 %D to i64 ret i64 %E -; CHECK: @test53 +; CHECK-LABEL: @test53( ; CHECK-NEXT: %B = zext i32 %A to i64 ; CHECK-NEXT: %C = and i64 %B, 7224 ; CHECK-NEXT: %D = or i64 %C, 32962 @@ -515,7 +531,7 @@ define i32 @test54(i64 %A) { %D = and i16 %C, -25350 %E = sext i16 %D to i32 ret i32 %E -; CHECK: @test54 +; CHECK-LABEL: @test54( ; CHECK-NEXT: %B = trunc i64 %A to i32 ; CHECK-NEXT: %C = and i32 %B, 7224 ; CHECK-NEXT: %D = or i32 %C, -32574 @@ -528,7 +544,7 @@ define i64 @test55(i32 %A) { %D = and i16 %C, -25350 %E = sext i16 %D to i64 ret i64 %E -; CHECK: @test55 +; CHECK-LABEL: @test55( ; CHECK-NEXT: %B = zext i32 %A to i64 ; CHECK-NEXT: %C = and i64 %B, 7224 ; CHECK-NEXT: %D = or i64 %C, -32574 @@ -540,7 +556,7 @@ define i64 @test56(i16 %A) nounwind { %tmp354 = lshr i32 %tmp353, 5 %tmp355 = zext i32 %tmp354 to i64 ret i64 %tmp355 -; CHECK: @test56 +; CHECK-LABEL: @test56( ; CHECK-NEXT: %tmp353 = sext i16 %A to i64 ; CHECK-NEXT: %tmp354 = lshr i64 %tmp353, 5 ; CHECK-NEXT: %tmp355 = and i64 %tmp354, 134217727 @@ -552,7 +568,7 @@ define i64 @test57(i64 %A) nounwind { %C = lshr i32 %B, 8 %E = zext i32 %C to i64 ret i64 %E -; CHECK: @test57 +; CHECK-LABEL: @test57( ; CHECK-NEXT: %C = lshr i64 %A, 8 ; CHECK-NEXT: %E = and i64 %C, 16777215 ; CHECK-NEXT: ret i64 %E @@ -565,7 +581,7 @@ define i64 @test58(i64 %A) nounwind { %E = zext i32 %D to i64 ret i64 %E -; CHECK: @test58 +; CHECK-LABEL: @test58( ; CHECK-NEXT: %C = lshr i64 %A, 8 ; CHECK-NEXT: %D = and i64 %C, 16777087 ; CHECK-NEXT: %E = or i64 %D, 128 @@ -581,7 +597,7 @@ define i64 @test59(i8 %A, i8 %B) nounwind { %H = or i32 %G, %E %I = zext i32 %H to i64 ret i64 %I -; CHECK: @test59 +; CHECK-LABEL: @test59( ; CHECK-NEXT: %C = zext i8 %A to i64 ; CHECK-NOT: i32 ; CHECK: %F = zext i8 %B to i64 @@ -595,7 +611,7 @@ define <3 x i32> @test60(<4 x i32> %call4) nounwind { %tmp10 = bitcast i96 %tmp9 to <3 x i32> ret <3 x i32> %tmp10 -; CHECK: @test60 +; CHECK-LABEL: @test60( ; CHECK-NEXT: shufflevector ; CHECK-NEXT: ret } @@ -605,7 +621,7 @@ define <4 x i32> @test61(<3 x i32> %call4) nounwind { %tmp9 = zext i96 %tmp11 to i128 %tmp10 = bitcast i128 %tmp9 to <4 x i32> ret <4 x i32> %tmp10 -; CHECK: @test61 +; CHECK-LABEL: @test61( ; CHECK-NEXT: shufflevector ; CHECK-NEXT: ret } @@ -615,7 +631,7 @@ define <4 x i32> @test62(<3 x float> %call4) nounwind { %tmp9 = zext i96 %tmp11 to i128 %tmp10 = bitcast i128 %tmp9 to <4 x i32> ret <4 x i32> %tmp10 -; CHECK: @test62 +; CHECK-LABEL: @test62( ; CHECK-NEXT: bitcast ; CHECK-NEXT: shufflevector ; CHECK-NEXT: ret @@ -627,7 +643,7 @@ entry: %a = bitcast i64 %tmp8 to <2 x i32> %vcvt.i = uitofp <2 x i32> %a to <2 x float> ret <2 x float> %vcvt.i -; CHECK: @test63 +; CHECK-LABEL: @test63( ; CHECK: bitcast ; CHECK: uitofp } @@ -636,7 +652,7 @@ define <4 x float> @test64(<4 x float> %c) nounwind { %t0 = bitcast <4 x float> %c to <4 x i32> %t1 = bitcast <4 x i32> %t0 to <4 x float> ret <4 x float> %t1 -; CHECK: @test64 +; CHECK-LABEL: @test64( ; CHECK-NEXT: ret <4 x float> %c } @@ -644,7 +660,7 @@ define <4 x float> @test65(<4 x float> %c) nounwind { %t0 = bitcast <4 x float> %c to <2 x double> %t1 = bitcast <2 x double> %t0 to <4 x float> ret <4 x float> %t1 -; CHECK: @test65 +; CHECK-LABEL: @test65( ; CHECK-NEXT: ret <4 x float> %c } @@ -652,13 +668,13 @@ define <2 x float> @test66(<2 x float> %c) nounwind { %t0 = bitcast <2 x float> %c to double %t1 = bitcast double %t0 to <2 x float> ret <2 x float> %t1 -; CHECK: @test66 +; CHECK-LABEL: @test66( ; CHECK-NEXT: ret <2 x float> %c } define float @test2c() { ret float extractelement (<2 x float> bitcast (double bitcast (<2 x float> to double) to <2 x float>), i32 0) -; CHECK: @test2c +; CHECK-LABEL: @test2c( ; CHECK-NOT: extractelement } @@ -667,7 +683,7 @@ define i64 @test_mmx(<2 x i32> %c) nounwind { %B = bitcast x86_mmx %A to <2 x i32> %C = bitcast <2 x i32> %B to i64 ret i64 %C -; CHECK: @test_mmx +; CHECK-LABEL: @test_mmx( ; CHECK-NOT: x86_mmx } @@ -676,7 +692,7 @@ define i64 @test_mmx_const(<2 x i32> %c) nounwind { %B = bitcast x86_mmx %A to <2 x i32> %C = bitcast <2 x i32> %B to i64 ret i64 %C -; CHECK: @test_mmx_const +; CHECK-LABEL: @test_mmx_const( ; CHECK-NOT: x86_mmx } @@ -691,14 +707,14 @@ define i1 @test67(i1 %a, i32 %b) { %trunc = trunc i32 %conv.i.i to i8 %tobool.i = icmp eq i8 %trunc, 0 ret i1 %tobool.i -; CHECK: @test67 +; CHECK-LABEL: @test67( ; CHECK: ret i1 false } %s = type { i32, i32, i32 } define %s @test68(%s *%p, i64 %i) { -; CHECK: @test68 +; CHECK-LABEL: @test68( %o = mul i64 %i, 12 %q = bitcast %s* %p to i8* %pp = getelementptr inbounds i8* %q, i64 %o @@ -710,8 +726,49 @@ define %s @test68(%s *%p, i64 %i) { ; CHECK-NEXT: ret %s } +; addrspacecasts should be eliminated. +define %s @test68_addrspacecast(%s* %p, i64 %i) { +; CHECK-LABEL: @test68_addrspacecast( +; CHECK-NEXT: getelementptr %s* +; CHECK-NEXT: load %s* +; CHECK-NEXT: ret %s + %o = mul i64 %i, 12 + %q = addrspacecast %s* %p to i8 addrspace(2)* + %pp = getelementptr inbounds i8 addrspace(2)* %q, i64 %o + %r = addrspacecast i8 addrspace(2)* %pp to %s* + %l = load %s* %r + ret %s %l +} + +define %s @test68_addrspacecast_2(%s* %p, i64 %i) { +; CHECK-LABEL: @test68_addrspacecast_2( +; CHECK-NEXT: getelementptr %s* %p +; CHECK-NEXT: addrspacecast +; CHECK-NEXT: load %s addrspace(1)* +; CHECK-NEXT: ret %s + %o = mul i64 %i, 12 + %q = addrspacecast %s* %p to i8 addrspace(2)* + %pp = getelementptr inbounds i8 addrspace(2)* %q, i64 %o + %r = addrspacecast i8 addrspace(2)* %pp to %s addrspace(1)* + %l = load %s addrspace(1)* %r + ret %s %l +} + +define %s @test68_as1(%s addrspace(1)* %p, i32 %i) { +; CHECK-LABEL: @test68_as1( + %o = mul i32 %i, 12 + %q = bitcast %s addrspace(1)* %p to i8 addrspace(1)* + %pp = getelementptr inbounds i8 addrspace(1)* %q, i32 %o +; CHECK-NEXT: getelementptr %s addrspace(1)* + %r = bitcast i8 addrspace(1)* %pp to %s addrspace(1)* + %l = load %s addrspace(1)* %r +; CHECK-NEXT: load %s addrspace(1)* + ret %s %l +; CHECK-NEXT: ret %s +} + define double @test69(double *%p, i64 %i) { -; CHECK: @test69 +; CHECK-LABEL: @test69( %o = shl nsw i64 %i, 3 %q = bitcast double* %p to i8* %pp = getelementptr inbounds i8* %q, i64 %o @@ -724,7 +781,7 @@ define double @test69(double *%p, i64 %i) { } define %s @test70(%s *%p, i64 %i) { -; CHECK: @test70 +; CHECK-LABEL: @test70( %o = mul nsw i64 %i, 36 ; CHECK-NEXT: mul nsw i64 %i, 3 %q = bitcast %s* %p to i8* @@ -738,7 +795,7 @@ define %s @test70(%s *%p, i64 %i) { } define double @test71(double *%p, i64 %i) { -; CHECK: @test71 +; CHECK-LABEL: @test71( %o = shl i64 %i, 5 ; CHECK-NEXT: shl i64 %i, 2 %q = bitcast double* %p to i8* @@ -752,8 +809,8 @@ define double @test71(double *%p, i64 %i) { } define double @test72(double *%p, i32 %i) { -; CHECK: @test72 - %so = mul nsw i32 %i, 8 +; CHECK-LABEL: @test72( + %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* @@ -767,8 +824,8 @@ define double @test72(double *%p, i32 %i) { } define double @test73(double *%p, i128 %i) { -; CHECK: @test73 - %lo = mul nsw i128 %i, 8 +; CHECK-LABEL: @test73( + %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* @@ -782,7 +839,7 @@ define double @test73(double *%p, i128 %i) { } define double @test74(double *%p, i64 %i) { -; CHECK: @test74 +; CHECK-LABEL: @test74( %q = bitcast double* %p to i64* %pp = getelementptr inbounds i64* %q, i64 %i ; CHECK-NEXT: getelementptr inbounds double* @@ -794,7 +851,7 @@ define double @test74(double *%p, i64 %i) { } define i32* @test75(i32* %p, i32 %x) { -; CHECK: @test75 +; CHECK-LABEL: @test75( %y = shl i32 %x, 3 ; CHECK-NEXT: shl i32 %x, 3 %z = sext i32 %y to i64 @@ -806,7 +863,7 @@ define i32* @test75(i32* %p, i32 %x) { } define %s @test76(%s *%p, i64 %i, i64 %j) { -; CHECK: @test76 +; CHECK-LABEL: @test76( %o = mul i64 %i, 12 %o2 = mul nsw i64 %o, %j ; CHECK-NEXT: %o2 = mul i64 %i, %j @@ -821,7 +878,7 @@ define %s @test76(%s *%p, i64 %i, i64 %j) { } define %s @test77(%s *%p, i64 %i, i64 %j) { -; CHECK: @test77 +; CHECK-LABEL: @test77( %o = mul nsw i64 %i, 36 %o2 = mul nsw i64 %o, %j ; CHECK-NEXT: %o = mul nsw i64 %i, 3 @@ -837,7 +894,7 @@ define %s @test77(%s *%p, i64 %i, i64 %j) { } define %s @test78(%s *%p, i64 %i, i64 %j, i32 %k, i32 %l, i128 %m, i128 %n) { -; CHECK: @test78 +; CHECK-LABEL: @test78( %a = mul nsw i32 %k, 36 ; CHECK-NEXT: mul nsw i32 %k, 3 %b = mul nsw i32 %a, %l @@ -865,7 +922,7 @@ define %s @test78(%s *%p, i64 %i, i64 %j, i32 %k, i32 %l, i128 %m, i128 %n) { } define %s @test79(%s *%p, i64 %i, i32 %j) { -; CHECK: @test79 +; CHECK-LABEL: @test79( %a = mul nsw i64 %i, 36 ; CHECK: mul nsw i64 %i, 36 %b = trunc i64 %a to i32 @@ -879,8 +936,8 @@ define %s @test79(%s *%p, i64 %i, i32 %j) { } define double @test80([100 x double]* %p, i32 %i) { -; CHECK: @test80 - %tmp = mul nsw i32 %i, 8 +; CHECK-LABEL: @test80( + %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 @@ -891,3 +948,148 @@ define double @test80([100 x double]* %p, i32 %i) { ret double %l ; CHECK-NEXT: ret double } + +define double @test80_addrspacecast([100 x double] addrspace(1)* %p, i32 %i) { +; CHECK-LABEL: @test80_addrspacecast( +; CHECK-NEXT: getelementptr [100 x double] addrspace(1)* %p +; CHECK-NEXT: load double addrspace(1)* +; CHECK-NEXT: ret double + %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)* + %l = load double addrspace(1)* %r + ret double %l +} + +define double @test80_addrspacecast_2([100 x double] addrspace(1)* %p, i32 %i) { +; CHECK-LABEL: @test80_addrspacecast_2( +; CHECK-NEXT: getelementptr [100 x double] addrspace(1)* +; CHECK-NEXT: addrspacecast double addrspace(1)* +; CHECK-NEXT: load double addrspace(3)* +; CHECK-NEXT: ret double + %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)* + %l = load double addrspace(3)* %r + ret double %l +} + +define double @test80_as1([100 x double] addrspace(1)* %p, i16 %i) { +; CHECK-LABEL: @test80_as1( + %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 +; CHECK-NEXT: getelementptr [100 x double] addrspace(1)* + %r = bitcast i8 addrspace(1)* %pp to double addrspace(1)* + %l = load double addrspace(1)* %r +; CHECK-NEXT: load double addrspace(1)* + ret double %l +; CHECK-NEXT: ret double +} + +define double @test81(double *%p, float %f) { + %i = fptosi float %f to i64 + %q = bitcast double* %p to i8* + %pp = getelementptr i8* %q, i64 %i + %r = bitcast i8* %pp to double* + %l = load double* %r + ret double %l +} + +define i64 @test82(i64 %A) nounwind { + %B = trunc i64 %A to i32 + %C = lshr i32 %B, 8 + %D = shl i32 %C, 9 + %E = zext i32 %D to i64 + ret i64 %E + +; CHECK-LABEL: @test82( +; CHECK-NEXT: [[REG:%[0-9]*]] = shl i64 %A, 1 +; CHECK-NEXT: %E = and i64 [[REG]], 4294966784 +; CHECK-NEXT: ret i64 %E +} + +; PR15959 +define i64 @test83(i16 %a, i64 %k) { + %conv = sext i16 %a to i32 + %sub = add nsw i64 %k, -1 + %sh_prom = trunc i64 %sub to i32 + %shl = shl i32 %conv, %sh_prom + %sh_prom1 = zext i32 %shl to i64 + ret i64 %sh_prom1 + +; CHECK-LABEL: @test83( +; 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]] +}