|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; RUN: opt -passes=memcpyopt -S %s -verify-memoryssa | FileCheck %s |
| 3 | + |
| 4 | +; Redundant memmove. |
| 5 | +define i32 @test() { |
| 6 | +; CHECK-LABEL: @test( |
| 7 | +; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16 |
| 8 | +; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 [[ARRAY]], i8 0, i64 104, i1 false) |
| 9 | +; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4 |
| 10 | +; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 [[ARRAY]], ptr noundef nonnull align 4 [[ARRAY_IDX]], i64 100, i1 false) |
| 11 | +; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY]], align 16 |
| 12 | +; CHECK-NEXT: ret i32 [[VAL]] |
| 13 | +; |
| 14 | + %array = alloca [26 x i32], align 16 |
| 15 | + call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 %array, i8 0, i64 104, i1 false) |
| 16 | + %array.idx = getelementptr inbounds i8, ptr %array, i64 4 |
| 17 | + call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 %array, ptr noundef nonnull align 4 %array.idx, i64 100, i1 false) |
| 18 | + %val = load i32, ptr %array, align 16 |
| 19 | + ret i32 %val |
| 20 | +} |
| 21 | + |
| 22 | +; Used memmmove, buffer is reset to zero. |
| 23 | +define i32 @test1() { |
| 24 | +; CHECK-LABEL: @test1( |
| 25 | +; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16 |
| 26 | +; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 [[ARRAY]], i8 0, i64 104, i1 false) |
| 27 | +; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4 |
| 28 | +; CHECK-NEXT: store i32 1, ptr [[ARRAY_IDX]], align 4 |
| 29 | +; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 [[ARRAY]], ptr noundef nonnull align 4 [[ARRAY_IDX]], i64 100, i1 false) |
| 30 | +; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY_IDX]], align 4 |
| 31 | +; CHECK-NEXT: ret i32 [[VAL]] |
| 32 | +; |
| 33 | + %array = alloca [26 x i32], align 16 |
| 34 | + call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 %array, i8 0, i64 104, i1 false) |
| 35 | + %array.idx = getelementptr inbounds i8, ptr %array, i64 4 |
| 36 | + store i32 1, ptr %array.idx |
| 37 | + call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 %array, ptr noundef nonnull align 4 %array.idx, i64 100, i1 false) |
| 38 | + %val = load i32, ptr %array.idx, align 4 |
| 39 | + ret i32 %val |
| 40 | +} |
| 41 | + |
| 42 | +; Used memmove, buffer clobbered by opaque. |
| 43 | +define i32 @test2() { |
| 44 | +; CHECK-LABEL: @test2( |
| 45 | +; CHECK-NEXT: [[ARRAY:%.*]] = alloca [25 x i32], align 16 |
| 46 | +; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) [[ARRAY]], i8 0, i64 100, i1 false) |
| 47 | +; CHECK-NEXT: call void @opaque(ptr noundef nonnull [[ARRAY]]) |
| 48 | +; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4 |
| 49 | +; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(96) [[ARRAY]], ptr noundef nonnull align 4 dereferenceable(96) [[ARRAY_IDX]], i64 96, i1 false) |
| 50 | +; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY]], align 16 |
| 51 | +; CHECK-NEXT: ret i32 [[VAL]] |
| 52 | +; |
| 53 | + %array = alloca [25 x i32], align 16 |
| 54 | + call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) %array, i8 0, i64 100, i1 false) |
| 55 | + call void @opaque(ptr noundef nonnull %array) |
| 56 | + %array.idx = getelementptr inbounds i8, ptr %array, i64 4 |
| 57 | + call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(96) %array, ptr noundef nonnull align 4 dereferenceable(96) %array.idx, i64 96, i1 false) |
| 58 | + %val = load i32, ptr %array, align 16 |
| 59 | + ret i32 %val |
| 60 | +} |
| 61 | + |
| 62 | +; Redundant memmove, but not within the same basic block. |
| 63 | +define i32 @test3() { |
| 64 | +; CHECK-LABEL: @test3( |
| 65 | +; CHECK-NEXT: entry: |
| 66 | +; CHECK-NEXT: [[ARRAY:%.*]] = alloca [26 x i32], align 16 |
| 67 | +; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 [[ARRAY]], i8 0, i64 104, i1 false) |
| 68 | +; CHECK-NEXT: [[ARRAY_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAY]], i64 4 |
| 69 | +; CHECK-NEXT: br label [[USE:%.*]] |
| 70 | +; CHECK: use: |
| 71 | +; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 [[ARRAY]], ptr noundef nonnull align 4 [[ARRAY_IDX]], i64 100, i1 false) |
| 72 | +; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[ARRAY]], align 16 |
| 73 | +; CHECK-NEXT: ret i32 [[VAL]] |
| 74 | +; |
| 75 | +entry: |
| 76 | + %array = alloca [26 x i32], align 16 |
| 77 | + call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 %array, i8 0, i64 104, i1 false) |
| 78 | + %array.idx = getelementptr inbounds i8, ptr %array, i64 4 |
| 79 | + br label %use |
| 80 | + |
| 81 | +use: ; preds = %entry |
| 82 | + call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 %array, ptr noundef nonnull align 4 %array.idx, i64 100, i1 false) |
| 83 | + %val = load i32, ptr %array, align 16 |
| 84 | + ret i32 %val |
| 85 | +} |
| 86 | + |
| 87 | +declare void @opaque(ptr) |
| 88 | +declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1) |
| 89 | +declare void @llvm.memmove.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind |
0 commit comments