1 ; RUN: opt < %s -cost-model -analyze -mtriple=systemz-unknown -mcpu=z13 | FileCheck %s 2 ; 3 ; Test that loads into operations that can fold one memory operand get zero 4 ; cost. In the case that both operands are loaded, one load should get a cost 5 ; value. 6 7 define void @add() { 8 %li32 = load i32, i32* undef 9 add i32 %li32, undef 10 11 %li32_0 = load i32, i32* undef 12 %li32_1 = load i32, i32* undef 13 add i32 %li32_0, %li32_1 14 15 %li64 = load i64, i64* undef 16 add i64 %li64, undef 17 18 %li64_0 = load i64, i64* undef 19 %li64_1 = load i64, i64* undef 20 add i64 %li64_0, %li64_1 21 22 ret void; 23 24 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef 25 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = add i32 %li32, undef 26 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef 27 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef 28 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = add i32 %li32_0, %li32_1 29 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef 30 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = add i64 %li64, undef 31 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef 32 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef 33 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = add i64 %li64_0, %li64_1 34 } 35 36 define void @sub() { 37 %li32 = load i32, i32* undef 38 sub i32 %li32, undef 39 40 %li32_0 = load i32, i32* undef 41 %li32_1 = load i32, i32* undef 42 sub i32 %li32_0, %li32_1 43 44 %li64 = load i64, i64* undef 45 sub i64 %li64, undef 46 47 %li64_0 = load i64, i64* undef 48 %li64_1 = load i64, i64* undef 49 sub i64 %li64_0, %li64_1 50 51 ret void; 52 53 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef 54 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = sub i32 %li32, undef 55 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef 56 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef 57 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = sub i32 %li32_0, %li32_1 58 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef 59 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = sub i64 %li64, undef 60 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef 61 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef 62 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = sub i64 %li64_0, %li64_1 63 } 64 65 define void @mul() { 66 %li32 = load i32, i32* undef 67 mul i32 %li32, undef 68 69 %li32_0 = load i32, i32* undef 70 %li32_1 = load i32, i32* undef 71 mul i32 %li32_0, %li32_1 72 73 %li64 = load i64, i64* undef 74 mul i64 %li64, undef 75 76 %li64_0 = load i64, i64* undef 77 %li64_1 = load i64, i64* undef 78 mul i64 %li64_0, %li64_1 79 80 ret void; 81 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef 82 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = mul i32 %li32, undef 83 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef 84 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef 85 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = mul i32 %li32_0, %li32_1 86 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef 87 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = mul i64 %li64, undef 88 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef 89 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef 90 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = mul i64 %li64_0, %li64_1 91 } 92 93 define void @sdiv() { 94 %li32 = load i32, i32* undef 95 sdiv i32 %li32, undef 96 97 %li32_0 = load i32, i32* undef 98 %li32_1 = load i32, i32* undef 99 sdiv i32 %li32_0, %li32_1 100 101 %li64 = load i64, i64* undef 102 sdiv i64 %li64, undef 103 104 %li64_0 = load i64, i64* undef 105 %li64_1 = load i64, i64* undef 106 sdiv i64 %li64_0, %li64_1 107 108 ret void; 109 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef 110 ; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %1 = sdiv i32 %li32, undef 111 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef 112 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef 113 ; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %2 = sdiv i32 %li32_0, %li32_1 114 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef 115 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = sdiv i64 %li64, undef 116 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef 117 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef 118 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = sdiv i64 %li64_0, %li64_1 119 } 120 121 define void @udiv() { 122 %li32 = load i32, i32* undef 123 udiv i32 %li32, undef 124 125 %li32_0 = load i32, i32* undef 126 %li32_1 = load i32, i32* undef 127 udiv i32 %li32_0, %li32_1 128 129 %li64 = load i64, i64* undef 130 udiv i64 %li64, undef 131 132 %li64_0 = load i64, i64* undef 133 %li64_1 = load i64, i64* undef 134 udiv i64 %li64_0, %li64_1 135 136 ret void; 137 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef 138 ; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %1 = udiv i32 %li32, undef 139 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef 140 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef 141 ; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %2 = udiv i32 %li32_0, %li32_1 142 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef 143 ; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %3 = udiv i64 %li64, undef 144 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef 145 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef 146 ; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %4 = udiv i64 %li64_0, %li64_1 147 } 148 149 define void @and() { 150 %li32 = load i32, i32* undef 151 and i32 %li32, undef 152 153 %li32_0 = load i32, i32* undef 154 %li32_1 = load i32, i32* undef 155 and i32 %li32_0, %li32_1 156 157 %li64 = load i64, i64* undef 158 and i64 %li64, undef 159 160 %li64_0 = load i64, i64* undef 161 %li64_1 = load i64, i64* undef 162 and i64 %li64_0, %li64_1 163 164 ret void; 165 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef 166 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = and i32 %li32, undef 167 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef 168 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef 169 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = and i32 %li32_0, %li32_1 170 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef 171 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = and i64 %li64, undef 172 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef 173 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef 174 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = and i64 %li64_0, %li64_1 175 } 176 177 define void @or() { 178 %li32 = load i32, i32* undef 179 or i32 %li32, undef 180 181 %li32_0 = load i32, i32* undef 182 %li32_1 = load i32, i32* undef 183 or i32 %li32_0, %li32_1 184 185 %li64 = load i64, i64* undef 186 or i64 %li64, undef 187 188 %li64_0 = load i64, i64* undef 189 %li64_1 = load i64, i64* undef 190 or i64 %li64_0, %li64_1 191 192 ret void; 193 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef 194 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = or i32 %li32, undef 195 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef 196 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef 197 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = or i32 %li32_0, %li32_1 198 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef 199 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = or i64 %li64, undef 200 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef 201 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef 202 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = or i64 %li64_0, %li64_1 203 } 204 205 define void @xor() { 206 %li32 = load i32, i32* undef 207 xor i32 %li32, undef 208 209 %li32_0 = load i32, i32* undef 210 %li32_1 = load i32, i32* undef 211 xor i32 %li32_0, %li32_1 212 213 %li64 = load i64, i64* undef 214 xor i64 %li64, undef 215 216 %li64_0 = load i64, i64* undef 217 %li64_1 = load i64, i64* undef 218 xor i64 %li64_0, %li64_1 219 220 ret void; 221 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef 222 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = xor i32 %li32, undef 223 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef 224 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef 225 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = xor i32 %li32_0, %li32_1 226 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef 227 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = xor i64 %li64, undef 228 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef 229 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef 230 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = xor i64 %li64_0, %li64_1 231 } 232 233 define void @icmp() { 234 %li32 = load i32, i32* undef 235 icmp eq i32 %li32, undef 236 237 %li32_0 = load i32, i32* undef 238 %li32_1 = load i32, i32* undef 239 icmp eq i32 %li32_0, %li32_1 240 241 %li64 = load i64, i64* undef 242 icmp eq i64 %li64, undef 243 244 %li64_0 = load i64, i64* undef 245 %li64_1 = load i64, i64* undef 246 icmp eq i64 %li64_0, %li64_1 247 248 ret void; 249 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef 250 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = icmp eq i32 %li32, undef 251 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef 252 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef 253 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = icmp eq i32 %li32_0, %li32_1 254 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef 255 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = icmp eq i64 %li64, undef 256 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef 257 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef 258 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = icmp eq i64 %li64_0, %li64_1 259 } 260