1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
4 target datalayout = "e-m:e-p:64:64:64-i64:64-f80:128-n8:16:32:64-S128"
6 define i32 @test_load_cast_combine_tbaa(ptr %ptr) {
7 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves TBAA.
8 ; CHECK-LABEL: @test_load_cast_combine_tbaa(
10 ; CHECK-NEXT: [[L1:%.*]] = load i32, ptr [[PTR:%.*]], align 4, !tbaa [[TBAA0:![0-9]+]]
11 ; CHECK-NEXT: ret i32 [[L1]]
14 %l = load float, ptr %ptr, !tbaa !0
15 %c = bitcast float %l to i32
19 define i32 @test_load_cast_combine_noalias(ptr %ptr) {
20 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves no-alias metadata.
21 ; CHECK-LABEL: @test_load_cast_combine_noalias(
23 ; CHECK-NEXT: [[L1:%.*]] = load i32, ptr [[PTR:%.*]], align 4, !alias.scope !3, !noalias !3
24 ; CHECK-NEXT: ret i32 [[L1]]
27 %l = load float, ptr %ptr, !alias.scope !3, !noalias !3
28 %c = bitcast float %l to i32
32 define float @test_load_cast_combine_range(ptr %ptr) {
33 ; Ensure (cast (load (...))) -> (load (cast (...))) drops range metadata. It
34 ; would be nice to preserve or update it somehow but this is hard when moving
36 ; CHECK-LABEL: @test_load_cast_combine_range(
38 ; CHECK-NEXT: [[L1:%.*]] = load float, ptr [[PTR:%.*]], align 4
39 ; CHECK-NEXT: ret float [[L1]]
42 %l = load i32, ptr %ptr, !range !6
43 %c = bitcast i32 %l to float
47 define i32 @test_load_cast_combine_invariant(ptr %ptr) {
48 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves invariant metadata.
49 ; CHECK-LABEL: @test_load_cast_combine_invariant(
51 ; CHECK-NEXT: [[L1:%.*]] = load i32, ptr [[PTR:%.*]], align 4, !invariant.load !6
52 ; CHECK-NEXT: ret i32 [[L1]]
55 %l = load float, ptr %ptr, !invariant.load !7
56 %c = bitcast float %l to i32
60 define i32 @test_load_cast_combine_nontemporal(ptr %ptr) {
61 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves nontemporal
63 ; CHECK-LABEL: @test_load_cast_combine_nontemporal(
65 ; CHECK-NEXT: [[L1:%.*]] = load i32, ptr [[PTR:%.*]], align 4, !nontemporal !7
66 ; CHECK-NEXT: ret i32 [[L1]]
69 %l = load float, ptr %ptr, !nontemporal !8
70 %c = bitcast float %l to i32
74 define ptr @test_load_cast_combine_align(ptr %ptr) {
75 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves align
77 ; CHECK-LABEL: @test_load_cast_combine_align(
79 ; CHECK-NEXT: [[L:%.*]] = load ptr, ptr [[PTR:%.*]], align 8, !align !8
80 ; CHECK-NEXT: ret ptr [[L]]
83 %l = load ptr, ptr %ptr, !align !9
87 define ptr @test_load_cast_combine_deref(ptr %ptr) {
88 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves dereferenceable
90 ; CHECK-LABEL: @test_load_cast_combine_deref(
92 ; CHECK-NEXT: [[L:%.*]] = load ptr, ptr [[PTR:%.*]], align 8, !dereferenceable !8
93 ; CHECK-NEXT: ret ptr [[L]]
96 %l = load ptr, ptr %ptr, !dereferenceable !9
100 define ptr @test_load_cast_combine_deref_or_null(ptr %ptr) {
101 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves
102 ; dereferenceable_or_null metadata.
103 ; CHECK-LABEL: @test_load_cast_combine_deref_or_null(
105 ; CHECK-NEXT: [[L:%.*]] = load ptr, ptr [[PTR:%.*]], align 8, !dereferenceable_or_null !8
106 ; CHECK-NEXT: ret ptr [[L]]
109 %l = load ptr, ptr %ptr, !dereferenceable_or_null !9
113 define void @test_load_cast_combine_loop(ptr %src, ptr %dst, i32 %n) {
114 ; Ensure (cast (load (...))) -> (load (cast (...))) preserves loop access
116 ; CHECK-LABEL: @test_load_cast_combine_loop(
118 ; CHECK-NEXT: br label [[LOOP:%.*]]
120 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
121 ; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[I]] to i64
122 ; CHECK-NEXT: [[SRC_GEP:%.*]] = getelementptr inbounds float, ptr [[SRC:%.*]], i64 [[TMP0]]
123 ; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[I]] to i64
124 ; CHECK-NEXT: [[DST_GEP:%.*]] = getelementptr inbounds i32, ptr [[DST:%.*]], i64 [[TMP1]]
125 ; CHECK-NEXT: [[L1:%.*]] = load i32, ptr [[SRC_GEP]], align 4, !llvm.access.group [[ACC_GRP9:![0-9]+]]
126 ; CHECK-NEXT: store i32 [[L1]], ptr [[DST_GEP]], align 4
127 ; CHECK-NEXT: [[I_NEXT]] = add i32 [[I]], 1
128 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_NEXT]], [[N:%.*]]
129 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT:%.*]], !llvm.loop [[LOOP1:![0-9]+]]
131 ; CHECK-NEXT: ret void
137 %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
138 %src.gep = getelementptr inbounds float, ptr %src, i32 %i
139 %dst.gep = getelementptr inbounds i32, ptr %dst, i32 %i
140 %l = load float, ptr %src.gep, !llvm.access.group !10
141 %c = bitcast float %l to i32
142 store i32 %c, ptr %dst.gep
143 %i.next = add i32 %i, 1
144 %cmp = icmp slt i32 %i.next, %n
145 br i1 %cmp, label %loop, label %exit, !llvm.loop !1
151 define void @test_load_cast_combine_nonnull(ptr %ptr) {
152 ; CHECK-LABEL: @test_load_cast_combine_nonnull(
154 ; CHECK-NEXT: [[P:%.*]] = load ptr, ptr [[PTR:%.*]], align 8, !nonnull !6
155 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[PTR]], i64 336
156 ; CHECK-NEXT: store ptr [[P]], ptr [[GEP]], align 8
157 ; CHECK-NEXT: ret void
160 %p = load ptr, ptr %ptr, !nonnull !{}
161 %gep = getelementptr ptr, ptr %ptr, i32 42
162 store ptr %p, ptr %gep
166 define i32 @test_load_cast_combine_noundef(ptr %ptr) {
167 ; CHECK-LABEL: @test_load_cast_combine_noundef(
168 ; CHECK-NEXT: [[L1:%.*]] = load i32, ptr [[PTR:%.*]], align 4, !noundef !6
169 ; CHECK-NEXT: ret i32 [[L1]]
171 %l = load float, ptr %ptr, !noundef !{}
172 %c = bitcast float %l to i32
176 !0 = !{!1, !1, i64 0}
177 !1 = !{!"scalar type", !2}
180 !4 = distinct !{!4, !5}
182 !6 = !{i32 0, i32 42}