[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / llvm / test / Transforms / InstCombine / load-store-forward.ll
blobc1a01454772f2174c72674f7e69fa286a4213d7c
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 define i8 @load_smaller_int(i16* %p) {
6 ; LITTLE-LABEL: @load_smaller_int(
7 ; LITTLE-NEXT:    store i16 258, i16* [[P:%.*]], align 2
8 ; LITTLE-NEXT:    ret i8 2
10 ; BIG-LABEL: @load_smaller_int(
11 ; BIG-NEXT:    store i16 258, i16* [[P:%.*]], align 2
12 ; BIG-NEXT:    ret i8 1
14   store i16 258, i16* %p
15   %p2 = bitcast i16* %p to i8*
16   %load = load i8, i8* %p2
17   ret i8 %load
20 ; This case can *not* be forwarded, as we only see part of the stored value.
21 define i32 @load_larger_int(i16* %p) {
22 ; CHECK-LABEL: @load_larger_int(
23 ; CHECK-NEXT:    store i16 258, i16* [[P:%.*]], align 2
24 ; CHECK-NEXT:    [[P2:%.*]] = bitcast i16* [[P]] to i32*
25 ; CHECK-NEXT:    [[LOAD:%.*]] = load i32, i32* [[P2]], align 4
26 ; CHECK-NEXT:    ret i32 [[LOAD]]
28   store i16 258, i16* %p
29   %p2 = bitcast i16* %p to i32*
30   %load = load i32, i32* %p2
31   ret i32 %load
34 define i32 @vec_store_load_first(i32* %p) {
35 ; CHECK-LABEL: @vec_store_load_first(
36 ; CHECK-NEXT:    [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
37 ; CHECK-NEXT:    store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
38 ; CHECK-NEXT:    ret i32 1
40   %p2 = bitcast i32* %p to <2 x i32>*
41   store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2
42   %load = load i32, i32* %p
43   ret i32 %load
46 define i17 @vec_store_load_first_odd_size(i17* %p) {
47 ; CHECK-LABEL: @vec_store_load_first_odd_size(
48 ; CHECK-NEXT:    [[P2:%.*]] = bitcast i17* [[P:%.*]] to <2 x i17>*
49 ; CHECK-NEXT:    store <2 x i17> <i17 1, i17 2>, <2 x i17>* [[P2]], align 8
50 ; CHECK-NEXT:    [[LOAD:%.*]] = load i17, i17* [[P]], align 4
51 ; CHECK-NEXT:    ret i17 [[LOAD]]
53   %p2 = bitcast i17* %p to <2 x i17>*
54   store <2 x i17> <i17 1, i17 2>, <2 x i17>* %p2
55   %load = load i17, i17* %p
56   ret i17 %load
59 define i32 @vec_store_load_first_constexpr(i32* %p) {
60 ; CHECK-LABEL: @vec_store_load_first_constexpr(
61 ; CHECK-NEXT:    [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
62 ; 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
63 ; CHECK-NEXT:    [[LOAD:%.*]] = load i32, i32* [[P]], align 4
64 ; CHECK-NEXT:    ret i32 [[LOAD]]
66   %p2 = bitcast i32* %p to <2 x i32>*
67   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
68   %load = load i32, i32* %p, align 4
69   ret i32 %load
72 define i32 @vec_store_load_second(i32* %p) {
73 ; CHECK-LABEL: @vec_store_load_second(
74 ; CHECK-NEXT:    [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
75 ; CHECK-NEXT:    store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
76 ; CHECK-NEXT:    [[P3:%.*]] = getelementptr i32, i32* [[P]], i64 1
77 ; CHECK-NEXT:    [[LOAD:%.*]] = load i32, i32* [[P3]], align 4
78 ; CHECK-NEXT:    ret i32 [[LOAD]]
80   %p2 = bitcast i32* %p to <2 x i32>*
81   store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2
82   %p3 = getelementptr i32, i32* %p, i64 1
83   %load = load i32, i32* %p3
84   ret i32 %load
87 define i64 @vec_store_load_whole(i32* %p) {
88 ; LITTLE-LABEL: @vec_store_load_whole(
89 ; LITTLE-NEXT:    [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
90 ; LITTLE-NEXT:    store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
91 ; LITTLE-NEXT:    ret i64 8589934593
93 ; BIG-LABEL: @vec_store_load_whole(
94 ; BIG-NEXT:    [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
95 ; BIG-NEXT:    store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
96 ; BIG-NEXT:    ret i64 4294967298
98   %p2 = bitcast i32* %p to <2 x i32>*
99   store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2
100   %p3 = bitcast i32* %p to i64*
101   %load = load i64, i64* %p3
102   ret i64 %load
105 define i32 @vec_store_load_overlap(i32* %p) {
106 ; CHECK-LABEL: @vec_store_load_overlap(
107 ; CHECK-NEXT:    [[P2:%.*]] = bitcast i32* [[P:%.*]] to <2 x i32>*
108 ; CHECK-NEXT:    store <2 x i32> <i32 1, i32 2>, <2 x i32>* [[P2]], align 8
109 ; CHECK-NEXT:    [[P3:%.*]] = bitcast i32* [[P]] to i8*
110 ; CHECK-NEXT:    [[P4:%.*]] = getelementptr i8, i8* [[P3]], i64 2
111 ; CHECK-NEXT:    [[P5:%.*]] = bitcast i8* [[P4]] to i32*
112 ; CHECK-NEXT:    [[LOAD:%.*]] = load i32, i32* [[P5]], align 2
113 ; CHECK-NEXT:    ret i32 [[LOAD]]
115   %p2 = bitcast i32* %p to <2 x i32>*
116   store <2 x i32> <i32 1, i32 2>, <2 x i32>* %p2
117   %p3 = bitcast i32* %p to i8*
118   %p4 = getelementptr i8, i8* %p3, i64 2
119   %p5 = bitcast i8* %p4 to i32*
120   %load = load i32, i32* %p5, align 2
121   ret i32 %load