|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals all --version 5 |
| 2 | +; RUN: opt -S -passes=early-cse < %s | FileCheck %s |
| 3 | + |
| 4 | +declare i8 @baz(i8, i8) |
| 5 | +declare i8 @baz_side_effects(i8, i8) |
| 6 | +declare i8 @buz(i8, i8) |
| 7 | + |
| 8 | +declare ptr @baz.ptr(i8, i8) |
| 9 | +declare i8 @buz.ptr(ptr, ptr) |
| 10 | + |
| 11 | +declare float @baz.fp(float, float) |
| 12 | +declare i8 @buz.fp(float, float) |
| 13 | +define i8 @same_parent_combine_diff_attrs(i8 %x, i8 %y) { |
| 14 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs( |
| 15 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 16 | +; CHECK-NEXT: [[C2:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR0:[0-9]+]] |
| 17 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 18 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C1]], i8 [[C2]]) |
| 19 | +; CHECK-NEXT: ret i8 [[R]] |
| 20 | +; |
| 21 | + %c1 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone |
| 22 | + %c0 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 23 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 24 | + ret i8 %r |
| 25 | + |
| 26 | +} |
| 27 | + |
| 28 | +define i8 @same_parent_combine_diff_attrs_needs_intersect(i8 %x, i8 %y) { |
| 29 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_needs_intersect( |
| 30 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 31 | +; CHECK-NEXT: [[C1:%.*]] = call nonnull ptr @baz.ptr(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 32 | +; CHECK-NEXT: [[C0:%.*]] = call ptr @baz.ptr(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 33 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.ptr(ptr [[C0]], ptr [[C1]]) |
| 34 | +; CHECK-NEXT: ret i8 [[R]] |
| 35 | +; |
| 36 | + %c1 = call nonnull ptr @baz.ptr(i8 noundef %x, i8 noundef %y) readnone |
| 37 | + %c0 = call ptr @baz.ptr(i8 %x, i8 noundef %y) readnone |
| 38 | + %r = call i8 @buz.ptr(ptr %c0, ptr %c1) |
| 39 | + ret i8 %r |
| 40 | + |
| 41 | +} |
| 42 | + |
| 43 | +define i8 @same_parent_combine_diff_attrs_fmf(float %x, float %y) { |
| 44 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_fmf( |
| 45 | +; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) { |
| 46 | +; CHECK-NEXT: [[C1:%.*]] = call nnan nsz float @baz.fp(float noundef [[X]], float noundef [[Y]]) #[[ATTR1:[0-9]+]] |
| 47 | +; CHECK-NEXT: [[C0:%.*]] = call nnan float @baz.fp(float [[X]], float noundef [[Y]]) #[[ATTR1]] |
| 48 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.fp(float [[C0]], float [[C1]]) |
| 49 | +; CHECK-NEXT: ret i8 [[R]] |
| 50 | +; |
| 51 | + %c1 = call nnan nsz float @baz.fp(float noundef %x, float noundef %y) readonly |
| 52 | + %c0 = call nnan float @baz.fp(float %x, float noundef %y) readonly |
| 53 | + %r = call i8 @buz.fp(float %c0, float %c1) |
| 54 | + ret i8 %r |
| 55 | + |
| 56 | +} |
| 57 | + |
| 58 | +define i8 @same_parent_combine_diff_attrs_fmf2(float %x, float %y) { |
| 59 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_fmf2( |
| 60 | +; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) { |
| 61 | +; CHECK-NEXT: [[C1:%.*]] = call nnan float @baz.fp(float noundef [[X]], float noundef [[Y]]) #[[ATTR0]] |
| 62 | +; CHECK-NEXT: [[C0:%.*]] = call nnan nsz float @baz.fp(float [[X]], float noundef [[Y]]) #[[ATTR0]] |
| 63 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.fp(float [[C0]], float [[C1]]) |
| 64 | +; CHECK-NEXT: ret i8 [[R]] |
| 65 | +; |
| 66 | + %c1 = call nnan float @baz.fp(float noundef %x, float noundef %y) readnone |
| 67 | + %c0 = call nnan nsz float @baz.fp(float %x, float noundef %y) readnone |
| 68 | + %r = call i8 @buz.fp(float %c0, float %c1) |
| 69 | + ret i8 %r |
| 70 | + |
| 71 | +} |
| 72 | + |
| 73 | +define i8 @same_parent_combine_diff_attrs_needs_intersect2(i8 %x, i8 %y) { |
| 74 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_needs_intersect2( |
| 75 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 76 | +; CHECK-NEXT: [[C1:%.*]] = call nonnull ptr @baz.ptr(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 77 | +; CHECK-NEXT: [[C0:%.*]] = call ptr @baz.ptr(i8 [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 78 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.ptr(ptr [[C0]], ptr [[C1]]) |
| 79 | +; CHECK-NEXT: ret i8 [[R]] |
| 80 | +; |
| 81 | + %c1 = call nonnull ptr @baz.ptr(i8 noundef %x, i8 noundef %y) readonly |
| 82 | + %c0 = call ptr @baz.ptr(i8 %x, i8 noundef %y) readonly |
| 83 | + %r = call i8 @buz.ptr(ptr %c0, ptr %c1) |
| 84 | + ret i8 %r |
| 85 | + |
| 86 | +} |
| 87 | + |
| 88 | +define i8 @same_parent_combine_diff_attrs_really_needs_intersect(i8 %x, i8 %y) { |
| 89 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_really_needs_intersect( |
| 90 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 91 | +; CHECK-NEXT: [[C1:%.*]] = call nonnull ptr @baz.ptr(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 92 | +; CHECK-NEXT: [[C0:%.*]] = call ptr @baz.ptr(i8 [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 93 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.ptr(ptr [[C0]], ptr noundef [[C1]]) |
| 94 | +; CHECK-NEXT: ret i8 [[R]] |
| 95 | +; |
| 96 | + %c1 = call nonnull ptr @baz.ptr(i8 noundef %x, i8 noundef %y) readonly |
| 97 | + %c0 = call ptr @baz.ptr(i8 %x, i8 noundef %y) readonly |
| 98 | + %r = call i8 @buz.ptr(ptr %c0, ptr noundef %c1) |
| 99 | + ret i8 %r |
| 100 | + |
| 101 | +} |
| 102 | + |
| 103 | +define i8 @same_parent_combine_diff_attrs_fail_side_effects(i8 %x, i8 %y) { |
| 104 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_fail_side_effects( |
| 105 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 106 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) |
| 107 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) |
| 108 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 109 | +; CHECK-NEXT: ret i8 [[R]] |
| 110 | +; |
| 111 | + %c1 = call i8 @baz(i8 noundef %x, i8 noundef %y) |
| 112 | + %c0 = call i8 @baz(i8 %x, i8 noundef %y) |
| 113 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 114 | + ret i8 %r |
| 115 | + |
| 116 | +} |
| 117 | + |
| 118 | +define i8 @same_parent_combine_diff_attrs_quasi_side_effects2(i8 %x, i8 %y) { |
| 119 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_quasi_side_effects2( |
| 120 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 121 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 122 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) |
| 123 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 124 | +; CHECK-NEXT: ret i8 [[R]] |
| 125 | +; |
| 126 | + %c1 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone |
| 127 | + %c0 = call i8 @baz(i8 %x, i8 noundef %y) |
| 128 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 129 | + ret i8 %r |
| 130 | + |
| 131 | +} |
| 132 | + |
| 133 | +define i8 @diff_parent_combine_diff_attrs(i1 %c, i8 %x, i8 %y) { |
| 134 | +; CHECK-LABEL: define i8 @diff_parent_combine_diff_attrs( |
| 135 | +; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 136 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 137 | +; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]] |
| 138 | +; CHECK: [[T]]: |
| 139 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 140 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 141 | +; CHECK-NEXT: ret i8 [[R]] |
| 142 | +; CHECK: [[F]]: |
| 143 | +; CHECK-NEXT: [[R2:%.*]] = add i8 [[C1]], 4 |
| 144 | +; CHECK-NEXT: ret i8 [[R2]] |
| 145 | +; |
| 146 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 147 | + br i1 %c, label %T, label %F |
| 148 | +T: |
| 149 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readonly |
| 150 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 151 | + ret i8 %r |
| 152 | +F: |
| 153 | + %r2 = add i8 %c1, 4 |
| 154 | + ret i8 %r2 |
| 155 | +} |
| 156 | + |
| 157 | +define i8 @diff_parent_combine_diff_attrs_preserves_return_attrs(i1 %c, i8 %x, i8 %y) { |
| 158 | +; CHECK-LABEL: define i8 @diff_parent_combine_diff_attrs_preserves_return_attrs( |
| 159 | +; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 160 | +; CHECK-NEXT: [[C1:%.*]] = call nonnull ptr @baz.ptr(i8 [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 161 | +; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]] |
| 162 | +; CHECK: [[T]]: |
| 163 | +; CHECK-NEXT: [[C0:%.*]] = call nonnull ptr @baz.ptr(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR1]] |
| 164 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz.ptr(ptr [[C0]], ptr noundef [[C1]]) |
| 165 | +; CHECK-NEXT: ret i8 [[R]] |
| 166 | +; CHECK: [[F]]: |
| 167 | +; CHECK-NEXT: ret i8 9 |
| 168 | +; |
| 169 | + %c1 = call nonnull ptr @baz.ptr(i8 %x, i8 noundef %y) readonly |
| 170 | + br i1 %c, label %T, label %F |
| 171 | +T: |
| 172 | + %c0 = call nonnull ptr @baz.ptr(i8 noundef %x, i8 noundef %y) readonly |
| 173 | + %r = call i8 @buz.ptr(ptr %c0, ptr noundef %c1) |
| 174 | + ret i8 %r |
| 175 | +F: |
| 176 | + ret i8 9 |
| 177 | +} |
| 178 | + |
| 179 | +define i8 @same_parent_combine_diff_attrs_todo(i8 %x, i8 %y) { |
| 180 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_todo( |
| 181 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 182 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 183 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR2:[0-9]+]] |
| 184 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 185 | +; CHECK-NEXT: ret i8 [[R]] |
| 186 | +; |
| 187 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 188 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone alwaysinline |
| 189 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 190 | + ret i8 %r |
| 191 | + |
| 192 | +} |
| 193 | + |
| 194 | +define i8 @same_parent_combine_diff_attrs_fail(i8 %x, i8 %y) { |
| 195 | +; CHECK-LABEL: define i8 @same_parent_combine_diff_attrs_fail( |
| 196 | +; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 197 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 198 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR3:[0-9]+]] |
| 199 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 200 | +; CHECK-NEXT: ret i8 [[R]] |
| 201 | +; |
| 202 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 203 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone strictfp |
| 204 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 205 | + ret i8 %r |
| 206 | + |
| 207 | +} |
| 208 | + |
| 209 | +define i8 @diff_parent_combine_diff_attrs_todo(i1 %c, i8 %x, i8 %y) { |
| 210 | +; CHECK-LABEL: define i8 @diff_parent_combine_diff_attrs_todo( |
| 211 | +; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 212 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 213 | +; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]] |
| 214 | +; CHECK: [[T]]: |
| 215 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR4:[0-9]+]] |
| 216 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 217 | +; CHECK-NEXT: ret i8 [[R]] |
| 218 | +; CHECK: [[F]]: |
| 219 | +; CHECK-NEXT: [[R2:%.*]] = add i8 [[C1]], 4 |
| 220 | +; CHECK-NEXT: ret i8 [[R2]] |
| 221 | +; |
| 222 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 223 | + br i1 %c, label %T, label %F |
| 224 | +T: |
| 225 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone optnone noinline |
| 226 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 227 | + ret i8 %r |
| 228 | +F: |
| 229 | + %r2 = add i8 %c1, 4 |
| 230 | + ret i8 %r2 |
| 231 | +} |
| 232 | + |
| 233 | +define i8 @diff_parent_combine_diff_attrs_fail(i1 %c, i8 %x, i8 %y) { |
| 234 | +; CHECK-LABEL: define i8 @diff_parent_combine_diff_attrs_fail( |
| 235 | +; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]) { |
| 236 | +; CHECK-NEXT: [[C1:%.*]] = call i8 @baz(i8 [[X]], i8 noundef [[Y]]) #[[ATTR0]] |
| 237 | +; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]] |
| 238 | +; CHECK: [[T]]: |
| 239 | +; CHECK-NEXT: [[C0:%.*]] = call i8 @baz(i8 noundef [[X]], i8 noundef [[Y]]) #[[ATTR3]] |
| 240 | +; CHECK-NEXT: [[R:%.*]] = call i8 @buz(i8 [[C0]], i8 [[C1]]) |
| 241 | +; CHECK-NEXT: ret i8 [[R]] |
| 242 | +; CHECK: [[F]]: |
| 243 | +; CHECK-NEXT: [[R2:%.*]] = add i8 [[C1]], 4 |
| 244 | +; CHECK-NEXT: ret i8 [[R2]] |
| 245 | +; |
| 246 | + %c1 = call i8 @baz(i8 %x, i8 noundef %y) readnone |
| 247 | + br i1 %c, label %T, label %F |
| 248 | +T: |
| 249 | + %c0 = call i8 @baz(i8 noundef %x, i8 noundef %y) readnone strictfp |
| 250 | + %r = call i8 @buz(i8 %c0, i8 %c1) |
| 251 | + ret i8 %r |
| 252 | +F: |
| 253 | + %r2 = add i8 %c1, 4 |
| 254 | + ret i8 %r2 |
| 255 | +} |
| 256 | + |
| 257 | +;. |
| 258 | +; CHECK: attributes #[[ATTR0]] = { memory(none) } |
| 259 | +; CHECK: attributes #[[ATTR1]] = { memory(read) } |
| 260 | +; CHECK: attributes #[[ATTR2]] = { alwaysinline memory(none) } |
| 261 | +; CHECK: attributes #[[ATTR3]] = { strictfp memory(none) } |
| 262 | +; CHECK: attributes #[[ATTR4]] = { noinline optnone memory(none) } |
| 263 | +;. |
0 commit comments