1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=memcpyopt -S -verify-memoryssa | FileCheck %s
4 ; Check that a call featuring a scalable-vector byval argument fed by a memcpy
5 ; doesn't crash the compiler. It previously assumed the byval type's size could
6 ; be represented as a known constant amount.
7 define void @byval_caller(ptr %P) {
8 ; CHECK-LABEL: @byval_caller(
9 ; CHECK-NEXT: [[A:%.*]] = alloca i8, align 1
10 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[A]], ptr align 4 [[P:%.*]], i64 8, i1 false)
11 ; CHECK-NEXT: call void @byval_callee(ptr byval(<vscale x 1 x i8>) align 1 [[A]])
12 ; CHECK-NEXT: ret void
15 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %a, ptr align 4 %P, i64 8, i1 false)
16 call void @byval_callee(ptr align 1 byval(<vscale x 1 x i8>) %a)
20 declare void @llvm.memcpy.p0.p0.i64(ptr align 4, ptr align 4, i64, i1)
21 declare void @byval_callee(ptr align 1 byval(<vscale x 1 x i8>))
23 ; Check that two scalable-vector stores (overlapping, with a constant offset)
24 ; do not crash the compiler when checked whether or not they can be merged into
25 ; a single memset. There was previously an assumption that the stored values'
26 ; sizes could be represented by a known constant amount.
27 define void @merge_stores_both_scalable(ptr %ptr) {
28 ; CHECK-LABEL: @merge_stores_both_scalable(
29 ; CHECK-NEXT: store <vscale x 1 x i8> zeroinitializer, ptr [[PTR:%.*]], align 1
30 ; CHECK-NEXT: [[PTR_NEXT:%.*]] = getelementptr i8, ptr [[PTR]], i64 1
31 ; CHECK-NEXT: store <vscale x 1 x i8> zeroinitializer, ptr [[PTR_NEXT]], align 1
32 ; CHECK-NEXT: ret void
34 store <vscale x 1 x i8> zeroinitializer, ptr %ptr
35 %ptr.next = getelementptr i8, ptr %ptr, i64 1
36 store <vscale x 1 x i8> zeroinitializer, ptr %ptr.next
40 ; As above, but where the base is scalable but the subsequent store(s) are not.
41 define void @merge_stores_first_scalable(ptr %ptr) {
42 ; CHECK-LABEL: @merge_stores_first_scalable(
43 ; CHECK-NEXT: store <vscale x 1 x i8> zeroinitializer, ptr [[PTR:%.*]], align 1
44 ; CHECK-NEXT: [[PTR_NEXT:%.*]] = getelementptr i8, ptr [[PTR]], i64 1
45 ; CHECK-NEXT: store i8 0, ptr [[PTR_NEXT]], align 1
46 ; CHECK-NEXT: ret void
48 store <vscale x 1 x i8> zeroinitializer, ptr %ptr
49 %ptr.next = getelementptr i8, ptr %ptr, i64 1
50 store i8 zeroinitializer, ptr %ptr.next
54 ; As above, but where the base is not scalable but the subsequent store(s) are.
55 define void @merge_stores_second_scalable(ptr %ptr) {
56 ; CHECK-LABEL: @merge_stores_second_scalable(
57 ; CHECK-NEXT: store i8 0, ptr [[PTR:%.*]], align 1
58 ; CHECK-NEXT: [[PTR_NEXT:%.*]] = getelementptr i8, ptr [[PTR]], i64 1
59 ; CHECK-NEXT: store <vscale x 1 x i8> zeroinitializer, ptr [[PTR_NEXT]], align 1
60 ; CHECK-NEXT: ret void
62 store i8 zeroinitializer, ptr %ptr
63 %ptr.next = getelementptr i8, ptr %ptr, i64 1
64 store <vscale x 1 x i8> zeroinitializer, ptr %ptr.next
68 ; Check that the call-slot optimization doesn't crash when encountering scalable types.
69 define void @callslotoptzn(<vscale x 4 x float> %val, ptr %out) {
70 ; CHECK-LABEL: @callslotoptzn(
71 ; CHECK-NEXT: [[ALLOC:%.*]] = alloca <vscale x 4 x float>, align 16
72 ; CHECK-NEXT: [[IDX:%.*]] = tail call <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
73 ; CHECK-NEXT: [[STRIDE:%.*]] = getelementptr inbounds float, ptr [[ALLOC]], <vscale x 4 x i32> [[IDX]]
74 ; CHECK-NEXT: call void @llvm.masked.scatter.nxv4f32.nxv4p0(<vscale x 4 x float> [[VAL:%.*]], <vscale x 4 x ptr> [[STRIDE]], i32 4, <vscale x 4 x i1> shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i32 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer))
75 ; CHECK-NEXT: [[LI:%.*]] = load <vscale x 4 x float>, ptr [[ALLOC]], align 4
76 ; CHECK-NEXT: store <vscale x 4 x float> [[LI]], ptr [[OUT:%.*]], align 4
77 ; CHECK-NEXT: ret void
79 %alloc = alloca <vscale x 4 x float>, align 16
80 %idx = tail call <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
81 %stride = getelementptr inbounds float, ptr %alloc, <vscale x 4 x i32> %idx
82 call void @llvm.masked.scatter.nxv4f32.nxv4p0f32(<vscale x 4 x float> %val, <vscale x 4 x ptr> %stride, i32 4, <vscale x 4 x i1> shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i32 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer))
83 %li = load <vscale x 4 x float>, ptr %alloc, align 4
84 store <vscale x 4 x float> %li, ptr %out, align 4
88 declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
89 declare void @llvm.masked.scatter.nxv4f32.nxv4p0f32(<vscale x 4 x float> , <vscale x 4 x ptr> , i32, <vscale x 4 x i1>)