Replace uses of getAllocatedType() in PromoteMemoryToRegister.cpp with type tracking from actual loads and stores. This makes the promotion logic more semantic - it now checks that all loads/stores use a consistent type rather than requiring them to match the alloca's declared type. Changes: - isAllocaPromotable() now tracks the first load/store type seen and ensures all subsequent accesses use the same type - AllocaInfo gains a ValueType field populated during AnalyzeAlloca() - PromoteMem2Reg tracks AllocaValueTypes alongside other per-alloca info - PHI nodes and UndefValues are created using the tracked type This is semantically more permissive - an alloca declared as i64 but only accessed as i32 is now promotable. This is correct because the alloca is just a blob of memory; what matters for Mem2Reg is consistent access patterns. Test changes: - asan-stack-safety.ll: Changed loads/stores to volatile to prevent promotion while preserving ASAN stack safety analysis behavior - SPIRV pointer tests (array-skips-gep.ll, load-struct.ll, store-struct.ll, store-to-array-first-element.ll): Added escape calls to prevent alloca promotion, as these tests verify SPIRV backend handling of Function-storage-class pointers Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
40 lines
1.6 KiB
LLVM
40 lines
1.6 KiB
LLVM
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - | FileCheck %s
|
|
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan %s -o - -filetype=obj | spirv-val %}
|
|
|
|
; CHECK-DAG: %[[#uint_ty:]] = OpTypeInt 32 0
|
|
; CHECK-DAG: %[[#uint_0:]] = OpConstant %[[#uint_ty]] 0{{$}}
|
|
; CHECK-DAG: %[[#int_10:]] = OpConstant %[[#uint_ty]] 10{{$}}
|
|
; CHECK-DAG: %[[#array_ty:]] = OpTypeArray %[[#uint_ty]] %[[#int_10]]
|
|
; CHECK-DAG: %[[#array_fp:]] = OpTypePointer Function %[[#array_ty]]
|
|
; CHECK-DAG: %[[#array_pp:]] = OpTypePointer Private %[[#array_ty]]
|
|
; CHECK-DAG: %[[#int_fp:]] = OpTypePointer Function %[[#uint_ty]]
|
|
; CHECK-DAG: %[[#int_pp:]] = OpTypePointer Private %[[#uint_ty]]
|
|
|
|
@gv = external addrspace(10) global [10 x i32]
|
|
; CHECK: %[[#gv:]] = OpVariable %[[#array_pp]] Private
|
|
|
|
define internal spir_func i32 @foo() #0 {
|
|
%array = alloca [10 x i32], align 4
|
|
; CHECK: %[[#array:]] = OpVariable %[[#array_fp:]] Function
|
|
|
|
; Direct load from the pointer index. This requires an OpAccessChain
|
|
%1 = load i32, ptr %array, align 4
|
|
; CHECK: %[[#ptr:]] = OpAccessChain %[[#int_fp]] %[[#array]] %[[#uint_0]]
|
|
; CHECK: %[[#val:]] = OpLoad %[[#uint_ty]] %[[#ptr]] Aligned 4
|
|
|
|
ret i32 %1
|
|
; CHECK: OpReturnValue %[[#val]]
|
|
}
|
|
|
|
attributes #0 = { optnone noinline }
|
|
|
|
define internal spir_func i32 @bar() {
|
|
; Direct load from the pointer index. This requires an OpAccessChain
|
|
%1 = load i32, ptr addrspace(10) @gv
|
|
; CHECK: %[[#ptr:]] = OpAccessChain %[[#int_pp]] %[[#gv]] %[[#uint_0]]
|
|
; CHECK: %[[#val:]] = OpLoad %[[#uint_ty]] %[[#ptr]] Aligned 4
|
|
|
|
ret i32 %1
|
|
; CHECK: OpReturnValue %[[#val]]
|
|
}
|