xref: /llvm-project/llvm/test/Transforms/InstCombine/tmp-alloca-bypass.ll (revision 4ab40eca080965c65802710e39adbb78c4ce7bde)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3
4; See https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20210412/904154.html
5; When replacing an allocation that is only modified by a memcpy/memmove from
6; a constant whose alignment is equal to or exceeds that of the allocation,
7; we also need to ensure that we actually can replace all uses of an alloca
8; with said constant. This matters because it could be e.g. a select between
9; two constants, that happens after the first use of an alloca.
10
11%t0 = type { ptr, i64 }
12
13@g0 = external constant %t0
14@g1 = external constant %t0
15define void @test(ptr %out) {
16; CHECK-LABEL: @test(
17; CHECK-NEXT:    [[I0:%.*]] = alloca [[T0:%.*]], align 8
18; CHECK-NEXT:    [[I2:%.*]] = call i1 @get_cond()
19; CHECK-NEXT:    [[I3:%.*]] = select i1 [[I2]], ptr @g0, ptr @g1
20; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) [[I0]], ptr noundef nonnull align 8 dereferenceable(16) [[I3]], i64 16, i1 false)
21; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) [[OUT:%.*]], ptr noundef nonnull align 8 dereferenceable(16) [[I0]], i64 16, i1 false)
22; CHECK-NEXT:    ret void
23;
24  %i0 = alloca %t0
25  %i2 = call i1 @get_cond()
26  %i3 = select i1 %i2, ptr @g0, ptr @g1
27  call void @llvm.memcpy.p0.p0.i64(ptr %i0, ptr %i3, i64 16, i1 false)
28  call void @llvm.memcpy.p0.p0.i64(ptr %out, ptr %i0, i64 16, i1 false)
29  ret void
30}
31
32define void @test2() {
33; CHECK-LABEL: @test2(
34; CHECK-NEXT:  bb:
35; CHECK-NEXT:    [[I:%.*]] = alloca [[T0:%.*]], align 8
36; CHECK-NEXT:    [[I1:%.*]] = call i32 @func(ptr undef)
37; CHECK-NEXT:    [[I2:%.*]] = icmp eq i32 [[I1]], 2503
38; CHECK-NEXT:    [[I3:%.*]] = select i1 [[I2]], ptr @g0, ptr @g1
39; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) [[I]], ptr noundef nonnull align 8 dereferenceable(16) [[I3]], i64 16, i1 false)
40; CHECK-NEXT:    [[I5:%.*]] = call i32 @func(ptr nonnull byval([[T0]]) [[I]])
41; CHECK-NEXT:    unreachable
42;
43bb:
44  %i = alloca %t0, align 8
45  %i1 = call i32 @func(ptr undef)
46  %i2 = icmp eq i32 %i1, 2503
47  %i3 = select i1 %i2, ptr @g0, ptr @g1
48  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %i, ptr noundef nonnull align 8 dereferenceable(16) %i3, i64 16, i1 false)
49  %i5 = call i32 @func(ptr nonnull byval(%t0) %i)
50  unreachable
51}
52
53declare i32 @func(ptr)
54declare i1 @get_cond()
55declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)
56