Skip to content

Commit eb8fcc1

Browse files
committed
[InstCombine] Add additional memcpy from constant test with phi (NFC)
This is the case that is safe to handle, but currently isn't.
1 parent a4699a4 commit eb8fcc1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

llvm/test/Transforms/InstCombine/ptr-replace-alloca.ll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,35 @@ join:
281281
ret i32 %v
282282
}
283283

284+
define i32 @addrspace_diff_remove_alloca(i1 %cond) {
285+
; CHECK-LABEL: @addrspace_diff_remove_alloca(
286+
; CHECK-NEXT: entry:
287+
; CHECK-NEXT: [[A:%.*]] = alloca [32 x i8], align 1
288+
; CHECK-NEXT: call void @llvm.memcpy.p0.p1.i64(ptr noundef nonnull align 1 dereferenceable(32) [[A]], ptr addrspace(1) noundef align 16 dereferenceable(32) @g2, i64 32, i1 false)
289+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [32 x i8], ptr [[A]], i64 0, i64 2
290+
; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF:%.*]], label [[JOIN:%.*]]
291+
; CHECK: if:
292+
; CHECK-NEXT: br label [[JOIN]]
293+
; CHECK: join:
294+
; CHECK-NEXT: [[PHI:%.*]] = phi ptr [ [[A]], [[IF]] ], [ [[GEP]], [[ENTRY:%.*]] ]
295+
; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[PHI]], align 4
296+
; CHECK-NEXT: ret i32 [[V]]
297+
;
298+
entry:
299+
%a = alloca [32 x i8]
300+
call void @llvm.memcpy.p0.p1.i64(ptr %a, ptr addrspace(1) @g2, i64 32, i1 false)
301+
%gep = getelementptr inbounds [32 x i8], ptr %a, i32 0, i32 2
302+
br i1 %cond, label %if, label %join
303+
304+
if:
305+
br label %join
306+
307+
join:
308+
%phi = phi ptr [ %a, %if ], [ %gep, %entry ]
309+
%v = load i32, ptr %phi
310+
ret i32 %v
311+
}
312+
284313
define i32 @phi_loop(i1 %c) {
285314
; CHECK-LABEL: @phi_loop(
286315
; CHECK-NEXT: entry:

0 commit comments

Comments
 (0)