1 ; RUN: opt -instcombine -S < %s | FileCheck %s
3 define i32 @test_load_cast_combine_tbaa(float* %ptr) {
4 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves TBAA.
5 ; CHECK-LABEL: @test_load_cast_combine_tbaa(
6 ; CHECK: load i32* %{{.*}}, !tbaa !0
8 %l = load float* %ptr, !tbaa !0
9 %c = bitcast float %l to i32
13 define i32 @test_load_cast_combine_noalias(float* %ptr) {
14 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves no-alias metadata.
15 ; CHECK-LABEL: @test_load_cast_combine_noalias(
16 ; CHECK: load i32* %{{.*}}, !alias.scope !2, !noalias !1
18 %l = load float* %ptr, !alias.scope !2, !noalias !1
19 %c = bitcast float %l to i32
23 define float @test_load_cast_combine_range(i32* %ptr) {
24 ; Ensure (cast (load (...))) -> (load (cast (...))) drops range metadata. It
25 ; would be nice to preserve or update it somehow but this is hard when moving
27 ; CHECK-LABEL: @test_load_cast_combine_range(
28 ; CHECK: load float* %{{.*}}
32 %l = load i32* %ptr, !range !5
33 %c = bitcast i32 %l to float
37 define i32 @test_load_cast_combine_invariant(float* %ptr) {
38 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves invariant metadata.
39 ; CHECK-LABEL: @test_load_cast_combine_invariant(
40 ; CHECK: load i32* %{{.*}}, !invariant.load !3
42 %l = load float* %ptr, !invariant.load !3
43 %c = bitcast float %l to i32
47 define i32 @test_load_cast_combine_nontemporal(float* %ptr) {
48 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves nontemporal
50 ; CHECK-LABEL: @test_load_cast_combine_nontemporal(
51 ; CHECK: load i32* %{{.*}}, !nontemporal !4
53 %l = load float* %ptr, !nontemporal !4
54 %c = bitcast float %l to i32
58 define void @test_load_cast_combine_loop(float* %src, i32* %dst, i32 %n) {
59 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves loop access
61 ; CHECK-LABEL: @test_load_cast_combine_loop(
62 ; CHECK: load i32* %{{.*}}, !llvm.mem.parallel_loop_access !1
67 %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
68 %src.gep = getelementptr inbounds float* %src, i32 %i
69 %dst.gep = getelementptr inbounds i32* %dst, i32 %i
70 %l = load float* %src.gep, !llvm.mem.parallel_loop_access !1
71 %c = bitcast float %l to i32
72 store i32 %c, i32* %dst.gep
73 %i.next = add i32 %i, 1
74 %cmp = icmp slt i32 %i.next, %n
75 br i1 %cmp, label %loop, label %exit, !llvm.loop !1
81 !0 = metadata !{ metadata !1, metadata !1, i64 0 }
82 !1 = metadata !{ metadata !1 }
83 !2 = metadata !{ metadata !2, metadata !1 }
85 !4 = metadata !{ i32 1 }
86 !5 = metadata !{ i32 0, i32 42 }