llvm-project/llvm/test/Transforms/MemCpyOpt/memcpy-gep-modification.ll
Nikita Popov c23b4fbdbb
[IR] Remove size argument from lifetime intrinsics (#150248)
Now that #149310 has restricted lifetime intrinsics to only work on
allocas, we can also drop the explicit size argument. Instead, the size
is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead.
We never used that capability, so we should remove the need to handle
that possibility everywhere (though many key places, including stack
coloring, did not actually respect this).
2025-08-08 11:09:34 +02:00

61 lines
2.7 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -passes=memcpyopt < %s -verify-memoryssa | FileCheck %s
%struct.MaskedType = type { i8, i8 }
declare void @llvm.lifetime.start.p0(ptr nocapture) #0
declare void @llvm.lifetime.end.p0(ptr nocapture) #0
declare void @MaskedFunction1(ptr, ptr addrspace(1))
declare void @MaskedFunction2(ptr, ptr)
define i8 @test_gep_not_modified(ptr %in0, ptr %in1) {
; CHECK-LABEL: @test_gep_not_modified(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[FUNCALLOC:%.*]] = alloca [[STRUCT_MASKEDTYPE:%.*]], align 4
; CHECK-NEXT: [[PTRALLOC:%.*]] = alloca i8, align 1
; CHECK-NEXT: call void @llvm.lifetime.start.p0(ptr [[PTRALLOC]])
; CHECK-NEXT: [[ADDRSPACECAST:%.*]] = addrspacecast ptr [[PTRALLOC]] to ptr addrspace(1)
; CHECK-NEXT: call void @MaskedFunction1(ptr [[IN1:%.*]], ptr addrspace(1) [[ADDRSPACECAST]])
; CHECK-NEXT: [[LOAD1:%.*]] = load i8, ptr [[PTRALLOC]], align 1
; CHECK-NEXT: call void @llvm.lifetime.end.p0(ptr [[PTRALLOC]])
; CHECK-NEXT: [[GETELEMPTR1:%.*]] = getelementptr inbounds [[STRUCT_MASKEDTYPE]], ptr [[FUNCALLOC]], i32 0, i32 1
; CHECK-NEXT: store i8 [[LOAD1]], ptr [[GETELEMPTR1]], align 1
; CHECK-NEXT: ret i8 0
;
entry:
%funcAlloc = alloca %struct.MaskedType, align 4
%ptrAlloc = alloca i8, align 1
call void @llvm.lifetime.start.p0(ptr %ptrAlloc) #0
%addrspaceCast = addrspacecast ptr %ptrAlloc to ptr addrspace(1)
call void @MaskedFunction1(ptr %in1, ptr addrspace(1) %addrspaceCast)
%load1 = load i8, ptr %ptrAlloc, align 1
call void @llvm.lifetime.end.p0(ptr %ptrAlloc) #0
%getElemPtr1 = getelementptr inbounds %struct.MaskedType, ptr %funcAlloc, i32 0, i32 1
store i8 %load1, ptr %getElemPtr1, align 1
ret i8 0
}
define i8 @test_gep_modified(ptr %in0, ptr %in1) {
; CHECK-LABEL: @test_gep_modified(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[FUNCALLOC:%.*]] = alloca [[STRUCT_MASKEDTYPE:%.*]], align 4
; CHECK-NEXT: [[PTRALLOC:%.*]] = alloca i8, align 1
; CHECK-NEXT: call void @llvm.lifetime.start.p0(ptr [[PTRALLOC]])
; CHECK-NEXT: [[GETELEMPTR1:%.*]] = getelementptr inbounds [[STRUCT_MASKEDTYPE]], ptr [[FUNCALLOC]], i32 0, i32 1
; CHECK-NEXT: call void @MaskedFunction2(ptr [[IN1:%.*]], ptr [[GETELEMPTR1]])
; CHECK-NEXT: call void @llvm.lifetime.end.p0(ptr [[PTRALLOC]])
; CHECK-NEXT: ret i8 0
;
entry:
%funcAlloc = alloca %struct.MaskedType, align 4
%ptrAlloc = alloca i8, align 1
call void @llvm.lifetime.start.p0(ptr %ptrAlloc) #0
call void @MaskedFunction2(ptr %in1, ptr %ptrAlloc)
%load1 = load i8, ptr %ptrAlloc, align 1
call void @llvm.lifetime.end.p0(ptr %ptrAlloc) #0
%getElemPtr1 = getelementptr inbounds %struct.MaskedType, ptr %funcAlloc, i32 0, i32 1
store i8 %load1, ptr %getElemPtr1, align 1
ret i8 0
}