Home | History | Annotate | Download | only in ScalarRepl
      1 ; RUN: opt < %s -scalarrepl -S | FileCheck %s
      2 target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
      3 @C.0.1248 = internal constant [128 x float] [ float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00 ], align 32		; <[128 x float]*> [#uses=1]
      4 
      5 define float @test1(i32 %hash, float %x, float %y, float %z, float %w) {
      6 entry:
      7 	%lookupTable = alloca [128 x float], align 16		; <[128 x float]*> [#uses=5]
      8 	%lookupTable1 = bitcast [128 x float]* %lookupTable to i8*		; <i8*> [#uses=1]
      9 	call void @llvm.memcpy.i32( i8* %lookupTable1, i8* bitcast ([128 x float]* @C.0.1248 to i8*), i32 512, i32 16 )
     10         
     11 ; CHECK: @test1
     12 ; CHECK-NOT: alloca
     13 ; CHECK-NOT: call{{.*}}@llvm.memcpy
     14 ; CHECK: %lookupTable1 = bitcast [128 x float]* @C.0.1248 to i8*
     15 ; CHECK-NOT: call{{.*}}@llvm.memcpy
     16         
     17 	%tmp3 = shl i32 %hash, 2		; <i32> [#uses=1]
     18 	%tmp5 = and i32 %tmp3, 124		; <i32> [#uses=4]
     19 	%tmp753 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp5		; <float*> [#uses=1]
     20 	%tmp9 = load float* %tmp753		; <float> [#uses=1]
     21 	%tmp11 = fmul float %tmp9, %x		; <float> [#uses=1]
     22 	%tmp13 = fadd float %tmp11, 0.000000e+00		; <float> [#uses=1]
     23 	%tmp17.sum52 = or i32 %tmp5, 1		; <i32> [#uses=1]
     24 	%tmp1851 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp17.sum52		; <float*> [#uses=1]
     25 	%tmp19 = load float* %tmp1851		; <float> [#uses=1]
     26 	%tmp21 = fmul float %tmp19, %y		; <float> [#uses=1]
     27 	%tmp23 = fadd float %tmp21, %tmp13		; <float> [#uses=1]
     28 	%tmp27.sum50 = or i32 %tmp5, 2		; <i32> [#uses=1]
     29 	%tmp2849 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp27.sum50		; <float*> [#uses=1]
     30 	%tmp29 = load float* %tmp2849		; <float> [#uses=1]
     31 	%tmp31 = fmul float %tmp29, %z		; <float> [#uses=1]
     32 	%tmp33 = fadd float %tmp31, %tmp23		; <float> [#uses=1]
     33 	%tmp37.sum48 = or i32 %tmp5, 3		; <i32> [#uses=1]
     34 	%tmp3847 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp37.sum48		; <float*> [#uses=1]
     35 	%tmp39 = load float* %tmp3847		; <float> [#uses=1]
     36 	%tmp41 = fmul float %tmp39, %w		; <float> [#uses=1]
     37 	%tmp43 = fadd float %tmp41, %tmp33		; <float> [#uses=1]
     38 	ret float %tmp43
     39 }
     40 
     41 declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
     42 
     43 
     44 
     45 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
     46 
     47 %T = type { i8, [123 x i8] }
     48 
     49 @G = constant %T {i8 1, [123 x i8] zeroinitializer }
     50 
     51 define void @test2() {
     52   %A = alloca %T
     53   %B = alloca %T
     54   %a = bitcast %T* %A to i8*
     55   %b = bitcast %T* %B to i8*
     56 
     57 ; CHECK: @test2
     58 
     59 ; %A alloca is deleted
     60 ; CHECK-NEXT: %B = alloca %T
     61 
     62 ; use @G instead of %A
     63 ; CHECK-NEXT: %a = bitcast %T* @G to i8*
     64   call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
     65   call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
     66   call void @bar(i8* %b)
     67   ret void
     68 }
     69 
     70 declare void @bar(i8*)
     71 
     72 
     73 ;; Should be able to eliminate the alloca.
     74 define void @test3() {
     75   %A = alloca %T
     76   %a = bitcast %T* %A to i8*
     77   call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
     78   call void @bar(i8* %a) readonly
     79 ; CHECK: @test3
     80 ; CHECK-NEXT: %a = bitcast %T* @G to i8*
     81 ; CHECK-NEXT: call void @bar(i8* %a)
     82   ret void
     83 }
     84 
     85 define void @test4() {
     86   %A = alloca %T
     87   %a = bitcast %T* %A to i8*
     88   call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
     89   call void @baz(i8* byval %a) 
     90 ; CHECK: @test4
     91 ; CHECK-NEXT: %a = bitcast %T* @G to i8*
     92 ; CHECK-NEXT: call void @baz(i8* byval %a)
     93   ret void
     94 }
     95 
     96 declare void @llvm.lifetime.start(i64, i8*)
     97 define void @test5() {
     98   %A = alloca %T
     99   %a = bitcast %T* %A to i8*
    100   call void @llvm.lifetime.start(i64 -1, i8* %a)
    101   call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
    102   call void @baz(i8* byval %a) 
    103 ; CHECK: @test5
    104 ; CHECK-NEXT: %a = bitcast %T* @G to i8*
    105 ; CHECK-NEXT: call void @baz(i8* byval %a)
    106   ret void
    107 }
    108 
    109 
    110 declare void @baz(i8* byval)
    111