1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
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.
11 %t0 = type { i8*, i64 }
13 @g0 = external constant %t0
14 @g1 = external constant %t0
15 define void @test(i8*%out) {
17 ; CHECK-NEXT: [[I0:%.*]] = alloca [[T0:%.*]], align 8
18 ; CHECK-NEXT: [[I1:%.*]] = bitcast %t0* [[I0]] to i8*
19 ; CHECK-NEXT: [[I2:%.*]] = call i1 @get_cond()
20 ; CHECK-NEXT: [[I3:%.*]] = select i1 [[I2]], i8* bitcast (%t0* @g0 to i8*), i8* bitcast (%t0* @g1 to i8*)
21 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 8 dereferenceable(16) [[I1]], i8* noundef nonnull align 8 dereferenceable(16) [[I3]], i64 16, i1 false)
22 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 1 dereferenceable(16) [[OUT:%.*]], i8* noundef nonnull align 8 dereferenceable(16) [[I1]], i64 16, i1 false)
23 ; CHECK-NEXT: ret void
26 %i1 = bitcast %t0* %i0 to i8*
27 %i2 = call i1 @get_cond()
28 %i3 = select i1 %i2, i8* bitcast (%t0* @g0 to i8*), i8* bitcast (%t0* @g1 to i8*)
29 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %i1, i8* %i3, i64 16, i1 false)
30 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %out, i8* %i1, i64 16, i1 false)
34 define void @test2() {
35 ; CHECK-LABEL: @test2(
37 ; CHECK-NEXT: [[I:%.*]] = alloca [[T0:%.*]], align 8
38 ; CHECK-NEXT: [[I1:%.*]] = call i32 @func(%t0* undef)
39 ; CHECK-NEXT: [[I2:%.*]] = icmp eq i32 [[I1]], 2503
40 ; CHECK-NEXT: [[I3:%.*]] = select i1 [[I2]], i8* bitcast (%t0* @g0 to i8*), i8* bitcast (%t0* @g1 to i8*)
41 ; CHECK-NEXT: [[I4:%.*]] = bitcast %t0* [[I]] to i8*
42 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 8 dereferenceable(16) [[I4]], i8* noundef nonnull align 8 dereferenceable(16) [[I3]], i64 16, i1 false)
43 ; CHECK-NEXT: [[I5:%.*]] = call i32 @func(%t0* nonnull byval([[T0]]) [[I]])
44 ; CHECK-NEXT: unreachable
47 %i = alloca %t0, align 8
48 %i1 = call i32 @func(%t0* undef)
49 %i2 = icmp eq i32 %i1, 2503
50 %i3 = select i1 %i2, i8* bitcast (%t0* @g0 to i8*), i8* bitcast (%t0* @g1 to i8*)
51 %i4 = bitcast %t0* %i to i8*
52 call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 8 dereferenceable(16) %i4, i8* noundef nonnull align 8 dereferenceable(16) %i3, i64 16, i1 false)
53 %i5 = call i32 @func(%t0* nonnull byval(%t0) %i)
57 declare i32 @func(%t0*)
58 declare i1 @get_cond()
59 declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i1)