1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s --check-prefixes=CHECK,LITTLE
3 ; RUN: opt -S -instcombine -data-layout="E" < %s | FileCheck %s --check-prefixes=CHECK,BIG
5 ; Some cases where store to load forwarding is principally possible,
8 define i8 @load_smaller_int(i16* %p) {
9 ; CHECK-LABEL: @load_smaller_int(
10 ; CHECK-NEXT: store i16 258, i16* [[P:%.*]], align 2
11 ; CHECK-NEXT: [[P2:%.*]] = bitcast i16* [[P]] to i8*
12 ; CHECK-NEXT: [[LOAD:%.*]] = load i8, i8* [[P2]], align 1
13 ; CHECK-NEXT: ret i8 [[LOAD]]
15 store i16 258, i16* %p
16 %p2 = bitcast i16* %p to i8*
17 %load = load i8, i8* %p2
21 define i32 @vec_store_load_first(i32* %p) {
22 ; CHECK-LABEL: @vec_store_load_first(
23 ; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
24 ; CHECK-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
25 ; CHECK-NEXT: ret i32 1
27 %p2 = bitcast i32* %p to <2 x i32>*
28 store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2
29 %load = load i32, i32* %p
33 define i17 @vec_store_load_first_odd_size(i17* %p) {
34 ; CHECK-LABEL: @vec_store_load_first_odd_size(
35 ; CHECK-NEXT: [[P2:%.*]] = bitcast i17* [[P:%.*]] to <2 x i17>*
36 ; CHECK-NEXT: store <2 x i17> <i17 1, i17 2>, <2 x i17>* [[P2]], align 8
37 ; CHECK-NEXT: ret i17 1
39 %p2 = bitcast i17* %p to <2 x i17>*
40 store <2 x i17> <i17 1, i17 2>, <2 x i17>* %p2
41 %load = load i17, i17* %p
45 define i32 @vec_store_load_first_constexpr(i32* %p) {
46 ; CHECK-LABEL: @vec_store_load_first_constexpr(
47 ; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
48 ; CHECK-NEXT: store <2 x i32> bitcast (i64 ptrtoint (i32 (i32*)* @vec_store_load_first to i64) to <2 x i32>), <2 x i32>* [[P2]], align 8
49 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P]], align 4
50 ; CHECK-NEXT: ret i32 [[LOAD]]
52 %p2 = bitcast i32* %p to <2 x i32>*
53 store <2 x i32> bitcast (i64 ptrtoint (i32 (i32*)* @vec_store_load_first to i64) to <2 x i32>), <2 x i32>* %p2, align 8
54 %load = load i32, i32* %p, align 4
58 define i32 @vec_store_load_second(i32* %p) {
59 ; CHECK-LABEL: @vec_store_load_second(
60 ; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
61 ; CHECK-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
62 ; CHECK-NEXT: [[P3:%.*]] = getelementptr i32, i32* [[P]], i64 1
63 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P3]], align 4
64 ; CHECK-NEXT: ret i32 [[LOAD]]
66 %p2 = bitcast i32* %p to <2 x i32>*
67 store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2
68 %p3 = getelementptr i32, i32* %p, i64 1
69 %load = load i32, i32* %p3
73 define i64 @vec_store_load_whole(i32* %p) {
74 ; LITTLE-LABEL: @vec_store_load_whole(
75 ; LITTLE-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
76 ; LITTLE-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
77 ; LITTLE-NEXT: ret i64 8589934593
79 ; BIG-LABEL: @vec_store_load_whole(
80 ; BIG-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
81 ; BIG-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
82 ; BIG-NEXT: ret i64 4294967298
84 %p2 = bitcast i32* %p to <2 x i32>*
85 store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2
86 %p3 = bitcast i32* %p to i64*
87 %load = load i64, i64* %p3
91 define i32 @vec_store_load_overlap(i32* %p) {
92 ; CHECK-LABEL: @vec_store_load_overlap(
93 ; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
94 ; CHECK-NEXT: store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
95 ; CHECK-NEXT: [[P3:%.*]] = bitcast i32* [[P]] to i8*
96 ; CHECK-NEXT: [[P4:%.*]] = getelementptr i8, i8* [[P3]], i64 2
97 ; CHECK-NEXT: [[P5:%.*]] = bitcast i8* [[P4]] to i32*
98 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P5]], align 2
99 ; CHECK-NEXT: ret i32 [[LOAD]]
101 %p2 = bitcast i32* %p to <2 x i32>*
102 store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2
103 %p3 = bitcast i32* %p to i8*
104 %p4 = getelementptr i8, i8* %p3, i64 2
105 %p5 = bitcast i8* %p4 to i32*
106 %load = load i32, i32* %p5, align 2