llvm-project
fa4c1ba1 - [SROA] Reject illegal vector memset promotion (#216772)

Commit
6 days ago
[SROA] Reject illegal vector memset promotion (#216772) SROA can select vector promotion for an `alloca` partition containing a memset and vector accesses whose element type is an unstable pointer. We discovered this while building Julia with LLVM 21 and assertions enabled. SROA crashed in `convertValue` because `canConvertValue` rejected converting an integer splat to a non-integral pointer: ``` Assertion `canConvertValue(DL, OldTy, NewTy, VScale) && "Value not convertable to type"' failed. ``` Current main no longer asserts because `convertValue` was replaced by `CreateBitPreservingCastChain`. However, the underlying unsupported transformation remains. For example: ```llvm target datalayout = "e-ni:10" declare void @llvm.memset.p0.i64(ptr, i8, i64, i1) define <2 x ptr addrspace(10)> @f( <2 x ptr addrspace(10)> %v, i8 %byte) { %a = alloca [2 x ptr addrspace(10)], align 8 store <2 x ptr addrspace(10)> %v, ptr %a, align 8 %p = getelementptr inbounds i8, ptr %a, i64 8 call void @llvm.memset.p0.i64(ptr %p, i8 %byte, i64 8, i1 false) %r = load <2 x ptr addrspace(10)>, ptr %a, align 8 ret <2 x ptr addrspace(10)> %r } ``` Running `opt -passes=sroa` on current main introduces: ```llvm %zext = zext i8 %byte to i64 %isplat = mul i64 %zext, 72340172838076673 %ptr = inttoptr i64 %isplat to ptr addrspace(10) ``` The legacy `ni:10` data-layout entry marks address space 10 as having an unstable pointer representation. AFAIU, optimizers may not introduce new dynamic `inttoptr` operations for such pointers. Fix: Check the integer-splat conversion during vector-promotion viability and reject the promotion when it cannot be converted to the vector element type. This leaves the original memory operations intact. Signed-off-by: Tim Besard <tim.besard@gmail.com>
Author
Parents
Loading