1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=memcpyopt -S %s -verify-memoryssa | FileCheck %s
; Redundant memmove.
define i32 @redundant_memmove() {
; CHECK-LABEL: @redundant_memmove(
; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[ARRAY]], i8 0, i64 104, i1 false)
; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY]], align 16
; CHECK-NEXT: ret i32 [[VAL]]
;
%array = alloca [26 x i32], align 16
call void @llvm.memset.p0.i64(ptr align 16 %array, i8 0, i64 104, i1 false)
%array.idx = getelementptr inbounds i8, ptr %array, i64 4
call void @llvm.memmove.p0.p0.i64(ptr align 16 %array, ptr align 4 %array.idx, i64 100, i1 false)
%val = load i32, ptr %array, align 16
ret i32 %val
}
; Used memmove, buffer is reset to zero.
define i32 @used_memmove_1() {
; CHECK-LABEL: @used_memmove_1(
; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[ARRAY]], i8 0, i64 104, i1 false)
; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4
; CHECK-NEXT: store i32 1, ptr [[ARRAY_IDX]], align 4
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 16 [[ARRAY]], ptr align 4 [[ARRAY_IDX]], i64 100, i1 false)
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY_IDX]], align 4
; CHECK-NEXT: ret i32 [[VAL]]
;
%array = alloca [26 x i32], align 16
call void @llvm.memset.p0.i64(ptr align 16 %array, i8 0, i64 104, i1 false)
%array.idx = getelementptr inbounds i8, ptr %array, i64 4
store i32 1, ptr %array.idx
call void @llvm.memmove.p0.p0.i64(ptr align 16 %array, ptr align 4 %array.idx, i64 100, i1 false)
%val = load i32, ptr %array.idx, align 4
ret i32 %val
}
; Used memmove.
define i32 @used_memmove_2() {
; CHECK-LABEL: @used_memmove_2(
; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[ARRAY]], i8 0, i64 104, i1 false)
; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4
; CHECK-NEXT: store i32 1, ptr [[ARRAY]], align 4
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 16 [[ARRAY]], ptr align 4 [[ARRAY_IDX]], i64 100, i1 false)
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY_IDX]], align 4
; CHECK-NEXT: ret i32 [[VAL]]
;
%array = alloca [26 x i32], align 16
call void @llvm.memset.p0.i64(ptr align 16 %array, i8 0, i64 104, i1 false)
%array.idx = getelementptr inbounds i8, ptr %array, i64 4
store i32 1, ptr %array
call void @llvm.memmove.p0.p0.i64(ptr align 16 %array, ptr align 4 %array.idx, i64 100, i1 false)
%val = load i32, ptr %array.idx, align 4
ret i32 %val
}
; Used memmove, buffer clobbered by opaque.
define i32 @used_memmove_3() {
; CHECK-LABEL: @used_memmove_3(
; CHECK-NEXT: [[ARRAY:%.*]] = alloca [25 x i32], align 16
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[ARRAY]], i8 0, i64 100, i1 false)
; CHECK-NEXT: call void @opaque(ptr [[ARRAY]])
; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 16 [[ARRAY]], ptr align 4 [[ARRAY_IDX]], i64 96, i1 false)
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY]], align 16
; CHECK-NEXT: ret i32 [[VAL]]
;
%array = alloca [25 x i32], align 16
call void @llvm.memset.p0.i64(ptr align 16 %array, i8 0, i64 100, i1 false)
call void @opaque(ptr %array)
%array.idx = getelementptr inbounds i8, ptr %array, i64 4
call void @llvm.memmove.p0.p0.i64(ptr align 16 %array, ptr align 4 %array.idx, i64 96, i1 false)
%val = load i32, ptr %array, align 16
ret i32 %val
}
; Redundant memmove, not within the same basic block.
define i32 @redundant_memmove_different_bbs() {
; CHECK-LABEL: @redundant_memmove_different_bbs(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[ARRAY]], i8 0, i64 104, i1 false)
; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4
; CHECK-NEXT: br label [[USE:%.*]]
; CHECK: use:
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY]], align 16
; CHECK-NEXT: ret i32 [[VAL]]
;
entry:
%array = alloca [26 x i32], align 16
call void @llvm.memset.p0.i64(ptr align 16 %array, i8 0, i64 104, i1 false)
%array.idx = getelementptr inbounds i8, ptr %array, i64 4
br label %use
use: ; preds = %entry
call void @llvm.memmove.p0.p0.i64(ptr align 16 %array, ptr align 4 %array.idx, i64 100, i1 false)
%val = load i32, ptr %array, align 16
ret i32 %val
}
@g_var = global [26 x i32] zeroinitializer, align 16
; Redundant memmove on a global variable.
define ptr @redundant_memmove_memset_global_variable() {
; CHECK-LABEL: @redundant_memmove_memset_global_variable(
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 @g_var, i8 0, i64 104, i1 false)
; CHECK-NEXT: ret ptr @g_var
;
call void @llvm.memset.p0.i64(ptr align 16 @g_var, i8 0, i64 104, i1 false)
call void @llvm.memmove.p0.p0.i64(ptr align 16 @g_var, ptr align 4 getelementptr inbounds nuw (i8, ptr @g_var, i64 4), i64 100, i1 false)
ret ptr @g_var
}
; Memset only partial.
define i32 @partial_memset() {
; CHECK-LABEL: @partial_memset(
; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16
; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 92
; CHECK-NEXT: store i32 1, ptr [[ARRAY_IDX]], align 4
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[ARRAY]], i8 0, i64 26, i1 false)
; CHECK-NEXT: [[ARRAY_IDX_2:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 16 [[ARRAY]], ptr align 4 [[ARRAY_IDX_2]], i64 100, i1 false)
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY_IDX]], align 4
; CHECK-NEXT: ret i32 [[VAL]]
;
%array = alloca [26 x i32], align 16
%array.idx = getelementptr inbounds i8, ptr %array, i64 92
store i32 1, ptr %array.idx
call void @llvm.memset.p0.i64(ptr align 16 %array, i8 0, i64 26, i1 false)
%array.idx.2 = getelementptr inbounds i8, ptr %array, i64 4
call void @llvm.memmove.p0.p0.i64(ptr align 16 %array, ptr align 4 %array.idx.2, i64 100, i1 false)
%val = load i32, ptr %array.idx, align 4
ret i32 %val
}
; Memset length not constant.
define i32 @memset_length_not_constant(i64 %size) {
; CHECK-LABEL: @memset_length_not_constant(
; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[ARRAY]], i8 0, i64 [[SIZE:%.*]], i1 false)
; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 16 [[ARRAY]], ptr align 4 [[ARRAY_IDX]], i64 100, i1 false)
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY]], align 16
; CHECK-NEXT: ret i32 [[VAL]]
;
%array = alloca [26 x i32], align 16
call void @llvm.memset.p0.i64(ptr align 16 %array, i8 0, i64 %size, i1 false)
%array.idx = getelementptr inbounds i8, ptr %array, i64 4
call void @llvm.memmove.p0.p0.i64(ptr align 16 %array, ptr align 4 %array.idx, i64 100, i1 false)
%val = load i32, ptr %array, align 16
ret i32 %val
}
; Memmove buffer not memset'd, different buffers.
define i32 @memset_memmove_dest_buffers_not_alias() {
; CHECK-LABEL: @memset_memmove_dest_buffers_not_alias(
; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16
; CHECK-NEXT: [[ARRAY2:%.*]] = alloca [26 x i32], align 16
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[ARRAY]], i8 0, i64 104, i1 false)
; CHECK-NEXT: [[ARRAY2_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY2]], i64 4
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 16 [[ARRAY2]], ptr align 4 [[ARRAY2_IDX]], i64 100, i1 false)
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY2]], align 16
; CHECK-NEXT: ret i32 [[VAL]]
;
%array = alloca [26 x i32], align 16
%array2 = alloca [26 x i32], align 16
call void @llvm.memset.p0.i64(ptr align 16 %array, i8 0, i64 104, i1 false)
%array2.idx = getelementptr inbounds i8, ptr %array2, i64 4
call void @llvm.memmove.p0.p0.i64(ptr align 16 %array2, ptr align 4 %array2.idx, i64 100, i1 false)
%val = load i32, ptr %array2, align 16
ret i32 %val
}
declare void @opaque(ptr)
declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1)
|