Jameson Nash 9d5d2eec21
[Mem2Reg] Remove extraneous getAllocatedType() check (#177438)
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>
2026-01-27 21:10:48 -05:00

67 lines
2.4 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:]] = OpTypeInt 32 0
; CHECK-DAG: %[[#float:]] = OpTypeFloat 32
; CHECK-DAG: %[[#float_fp:]] = OpTypePointer Function %[[#float]]
; CHECK-DAG: %[[#float_pp:]] = OpTypePointer Private %[[#float]]
; CHECK-DAG: %[[#uint_fp:]] = OpTypePointer Function %[[#uint]]
; CHECK-DAG: %[[#uint_0:]] = OpConstant %[[#uint]] 0
; CHECK-DAG: %[[#sf:]] = OpTypeStruct %[[#float]]
; CHECK-DAG: %[[#su:]] = OpTypeStruct %[[#uint]]
; CHECK-DAG: %[[#sfuf:]] = OpTypeStruct %[[#float]] %[[#uint]] %[[#float]]
; CHECK-DAG: %[[#sf_fp:]] = OpTypePointer Function %[[#sf]]
; CHECK-DAG: %[[#su_fp:]] = OpTypePointer Function %[[#su]]
; CHECK-DAG: %[[#sfuf_fp:]] = OpTypePointer Function %[[#sfuf]]
; CHECK-DAG: %[[#sfuf_pp:]] = OpTypePointer Private %[[#sfuf]]
%struct.SF = type { float }
%struct.SU = type { i32 }
%struct.SFUF = type { float, i32, float }
@gsfuf = external addrspace(10) global %struct.SFUF
; CHECK: %[[#gsfuf:]] = OpVariable %[[#sfuf_pp]] Private
define internal spir_func float @foo() #0 {
%1 = alloca %struct.SF, align 4
; CHECK: %[[#var:]] = OpVariable %[[#sf_fp]] Function
%2 = load float, ptr %1, align 4
; CHECK: %[[#tmp:]] = OpAccessChain %[[#float_fp]] %[[#var]] %[[#uint_0]]
; CHECK: %[[#val:]] = OpLoad %[[#float]] %[[#tmp]] Aligned 4
ret float %2
}
define internal spir_func i32 @bar() #0 {
%1 = alloca %struct.SU, align 4
; CHECK: %[[#var:]] = OpVariable %[[#su_fp]] Function
%2 = load i32, ptr %1, align 4
; CHECK: %[[#tmp:]] = OpAccessChain %[[#uint_fp]] %[[#var]] %[[#uint_0]]
; CHECK: %[[#val:]] = OpLoad %[[#uint]] %[[#tmp]] Aligned 4
ret i32 %2
}
define internal spir_func float @baz() #0 {
%1 = alloca %struct.SFUF, align 4
; CHECK: %[[#var:]] = OpVariable %[[#sfuf_fp]] Function
%2 = load float, ptr %1, align 4
; CHECK: %[[#tmp:]] = OpAccessChain %[[#float_fp]] %[[#var]] %[[#uint_0]]
; CHECK: %[[#val:]] = OpLoad %[[#float]] %[[#tmp]] Aligned 4
ret float %2
}
define internal spir_func float @biz() #0 {
%2 = load float, ptr addrspace(10) @gsfuf, align 4
; CHECK: %[[#tmp:]] = OpAccessChain %[[#float_pp]] %[[#gsfuf]] %[[#uint_0]]
; CHECK: %[[#val:]] = OpLoad %[[#float]] %[[#tmp]] Aligned 4
ret float %2
}
attributes #0 = { optnone noinline }