Home | History | Annotate | Download | only in InstCombine
      1 ; This test makes sure that memmove instructions are properly eliminated.
      2 ;
      3 ; RUN: opt < %s -instcombine -S | FileCheck %s
      4 
      5 @S = internal constant [33 x i8] c"panic: restorelist inconsistency\00"		; <[33 x i8]*> [#uses=1]
      6 @h = constant [2 x i8] c"h\00"		; <[2 x i8]*> [#uses=1]
      7 @hel = constant [4 x i8] c"hel\00"		; <[4 x i8]*> [#uses=1]
      8 @hello_u = constant [8 x i8] c"hello_u\00"		; <[8 x i8]*> [#uses=1]
      9 
     10 define void @test1(i8* %A, i8* %B, i32 %N) {
     11   ;; CHECK-LABEL: test1
     12   ;; CHECK-NEXT: ret void
     13   call void @llvm.memmove.p0i8.p0i8.i32(i8* %A, i8* %B, i32 0, i1 false)
     14   ret void
     15 }
     16 
     17 define void @test2(i8* %A, i32 %N) {
     18   ;; dest can't alias source since we can't write to source!
     19   ;; CHECK-LABEL: test2
     20   ;; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %A, i8* align 16 getelementptr inbounds ([33 x i8], [33 x i8]* @S, i{{32|64}} 0, i{{32|64}} 0), i32 %N, i1 false)
     21   ;; CHECK-NEXT: ret void
     22   call void @llvm.memmove.p0i8.p0i8.i32(i8* %A, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @S, i32 0, i32 0), i32 %N, i1 false)
     23   ret void
     24 }
     25 
     26 define i32 @test3([1024 x i8]* %target) { ; arg: [1024 x i8]*> [#uses=1]
     27   ;; CHECK-LABEL: test3
     28   ;; CHECK-NEXT: [[P1:%[^\s]+]] = bitcast [1024 x i8]* %target to i16*
     29   ;; CHECK-NEXT: store i16 104, i16* [[P1]], align 2
     30   ;; CHECK-NEXT: [[P2:%[^\s]+]] = bitcast [1024 x i8]* %target to i32*
     31   ;; CHECK-NEXT: store i32 7103848, i32* [[P2]], align 4
     32   ;; CHECK-NEXT: [[P3:%[^\s]+]] = bitcast [1024 x i8]* %target to i64*
     33   ;; CHECK-NEXT: store i64 33037504440198504, i64* [[P3]], align 8
     34   ;; CHECK-NEXT: ret i32 0
     35   %h_p = getelementptr [2 x i8], [2 x i8]* @h, i32 0, i32 0		; <i8*> [#uses=1]
     36   %hel_p = getelementptr [4 x i8], [4 x i8]* @hel, i32 0, i32 0		; <i8*> [#uses=1]
     37   %hello_u_p = getelementptr [8 x i8], [8 x i8]* @hello_u, i32 0, i32 0		; <i8*> [#uses=1]
     38   %target_p = getelementptr [1024 x i8], [1024 x i8]* %target, i32 0, i32 0		; <i8*> [#uses=3]
     39   call void @llvm.memmove.p0i8.p0i8.i32(i8* align 2 %target_p, i8* align 2 %h_p, i32 2, i1 false)
     40   call void @llvm.memmove.p0i8.p0i8.i32(i8* align 4 %target_p, i8* align 4 %hel_p, i32 4, i1 false)
     41   call void @llvm.memmove.p0i8.p0i8.i32(i8* align 8 %target_p, i8* align 8 %hello_u_p, i32 8, i1 false)
     42   ret i32 0
     43 }
     44 
     45 ; PR2370
     46 define void @test4(i8* %a) {
     47   ;; CHECK-LABEL: test4
     48   ;; CHECK-NEXT: ret void
     49   tail call void @llvm.memmove.p0i8.p0i8.i32(i8* %a, i8* %a, i32 100, i1 false)
     50   ret void
     51 }
     52 
     53 declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i1) argmemonly nounwind
     54