1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -dse -enable-dse-partial-store-merging -S < %s | FileCheck %s
3 target datalayout = "E-m:e-i64:64-i128:128-n32:64-S128"
5 define void @byte_by_byte_replacement(i32 *%ptr) {
6 ; CHECK-LABEL: @byte_by_byte_replacement(
8 ; CHECK-NEXT: store i32 151653132, i32* [[PTR:%.*]]
12 ;; This store's value should be modified as it should be better to use one
13 ;; larger store than several smaller ones.
14 ;; store will turn into 0x090A0B0C == 151653132
15 store i32 305419896, i32* %ptr ; 0x12345678
16 %bptr = bitcast i32* %ptr to i8*
17 %bptr1 = getelementptr inbounds i8, i8* %bptr, i64 1
18 %bptr2 = getelementptr inbounds i8, i8* %bptr, i64 2
19 %bptr3 = getelementptr inbounds i8, i8* %bptr, i64 3
21 ;; We should be able to merge these four stores with the i32 above
22 ; value (and bytes) stored before ; 0x12345678
23 store i8 9, i8* %bptr ; 09
24 store i8 10, i8* %bptr1 ; 0A
25 store i8 11, i8* %bptr2 ; 0B
26 store i8 12, i8* %bptr3 ; 0C
32 define void @word_replacement(i64 *%ptr) {
33 ; CHECK-LABEL: @word_replacement(
35 ; CHECK-NEXT: store i64 72638273700655232, i64* [[PTR:%.*]]
36 ; CHECK-NEXT: ret void
39 store i64 72623859790382856, i64* %ptr ; 0x0102030405060708
41 %wptr = bitcast i64* %ptr to i16*
42 %wptr1 = getelementptr inbounds i16, i16* %wptr, i64 1
43 %wptr3 = getelementptr inbounds i16, i16* %wptr, i64 3
45 ;; We should be able to merge these two stores with the i64 one above
46 ; value (and bytes) stored before ; 0x0102030405060708
47 store i16 4128, i16* %wptr1 ; 1020
48 store i16 28800, i16* %wptr3 ; 7080
55 define void @differently_sized_replacements(i64 *%ptr) {
56 ; CHECK-LABEL: @differently_sized_replacements(
58 ; CHECK-NEXT: store i64 289077004501059343, i64* [[PTR:%.*]]
59 ; CHECK-NEXT: ret void
62 store i64 579005069656919567, i64* %ptr ; 0x08090a0b0c0d0e0f
64 %bptr = bitcast i64* %ptr to i8*
65 %bptr6 = getelementptr inbounds i8, i8* %bptr, i64 6
66 %wptr = bitcast i64* %ptr to i16*
67 %wptr2 = getelementptr inbounds i16, i16* %wptr, i64 2
68 %dptr = bitcast i64* %ptr to i32*
70 ;; We should be able to merge all these stores with the i64 one above
71 ; value (and bytes) stored before ; 0x08090a0b0c0d0e0f
72 store i8 7, i8* %bptr6 ; 07
73 store i16 1541, i16* %wptr2 ; 0605
74 store i32 67305985, i32* %dptr ; 04030201
80 define void @multiple_replacements_to_same_byte(i64 *%ptr) {
81 ; CHECK-LABEL: @multiple_replacements_to_same_byte(
83 ; CHECK-NEXT: store i64 289077004602248719, i64* [[PTR:%.*]]
84 ; CHECK-NEXT: ret void
87 store i64 579005069656919567, i64* %ptr ; 0x08090a0b0c0d0e0f
89 %bptr = bitcast i64* %ptr to i8*
90 %bptr3 = getelementptr inbounds i8, i8* %bptr, i64 3
91 %wptr = bitcast i64* %ptr to i16*
92 %wptr1 = getelementptr inbounds i16, i16* %wptr, i64 1
93 %dptr = bitcast i64* %ptr to i32*
95 ;; We should be able to merge all these stores with the i64 one above
96 ; value (and bytes) stored before ; 0x08090a0b0c0d0e0f
97 store i8 7, i8* %bptr3 ; 07
98 store i16 1541, i16* %wptr1 ; 0605
99 store i32 67305985, i32* %dptr ; 04030201
104 define void @merged_merges(i64 *%ptr) {
105 ; CHECK-LABEL: @merged_merges(
107 ; CHECK-NEXT: store i64 289081428418563599, i64* [[PTR:%.*]]
108 ; CHECK-NEXT: ret void
111 store i64 579005069656919567, i64* %ptr ; 0x08090a0b0c0d0e0f
113 %bptr = bitcast i64* %ptr to i8*
114 %bptr3 = getelementptr inbounds i8, i8* %bptr, i64 3
115 %wptr = bitcast i64* %ptr to i16*
116 %wptr1 = getelementptr inbounds i16, i16* %wptr, i64 1
117 %dptr = bitcast i64* %ptr to i32*
119 ;; We should be able to merge all these stores with the i64 one above
120 ; value (not bytes) stored before ; 0x08090a0b0c0d0e0f
121 store i32 67305985, i32* %dptr ; 04030201
122 store i16 1541, i16* %wptr1 ; 0605
123 store i8 7, i8* %bptr3 ; 07
128 define signext i8 @shouldnt_merge_since_theres_a_full_overlap(i64 *%ptr) {
129 ; CHECK-LABEL: @shouldnt_merge_since_theres_a_full_overlap(
131 ; CHECK-NEXT: [[BPTR:%.*]] = bitcast i64* [[PTR:%.*]] to i8*
132 ; CHECK-NEXT: [[BPTRM1:%.*]] = getelementptr inbounds i8, i8* [[BPTR]], i64 -1
133 ; CHECK-NEXT: [[BPTR3:%.*]] = getelementptr inbounds i8, i8* [[BPTR]], i64 3
134 ; CHECK-NEXT: [[DPTR:%.*]] = bitcast i8* [[BPTRM1]] to i32*
135 ; CHECK-NEXT: [[QPTR:%.*]] = bitcast i8* [[BPTR3]] to i64*
136 ; CHECK-NEXT: store i32 1234, i32* [[DPTR]], align 1
137 ; CHECK-NEXT: store i64 5678, i64* [[QPTR]], align 1
138 ; CHECK-NEXT: ret i8 0
142 store i64 0, i64* %ptr
144 %bptr = bitcast i64* %ptr to i8*
145 %bptrm1 = getelementptr inbounds i8, i8* %bptr, i64 -1
146 %bptr3 = getelementptr inbounds i8, i8* %bptr, i64 3
147 %dptr = bitcast i8* %bptrm1 to i32*
148 %qptr = bitcast i8* %bptr3 to i64*
150 store i32 1234, i32* %dptr, align 1
151 store i64 5678, i64* %qptr, align 1
156 ;; Test case from PR31777
157 %union.U = type { i64 }
159 define void @foo(%union.U* nocapture %u) {
162 ; CHECK-NEXT: [[I:%.*]] = getelementptr inbounds [[UNION_U:%.*]], %union.U* [[U:%.*]], i64 0, i32 0
163 ; CHECK-NEXT: store i64 11821949021847552, i64* [[I]], align 8
164 ; CHECK-NEXT: ret void
167 %i = getelementptr inbounds %union.U, %union.U* %u, i64 0, i32 0
168 store i64 0, i64* %i, align 8
169 %s = bitcast %union.U* %u to i16*
170 store i16 42, i16* %s, align 8