From b29dbbd44593ae862772aa1311f00932f2c97483 Mon Sep 17 00:00:00 2001 From: David Green Date: Wed, 17 Sep 2025 06:50:06 +0100 Subject: [PATCH] [BasicAA] Handle scalable vectors in new errno aliasing checks. This is a minor fixup for scalable vectors after f9f62ef4ae555a. It handles them in the same way as other memory locations that are larger than errno, preventing the failure on implicit conversion from a scalable location. --- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 3 +- .../Transforms/InstCombine/may-alias-errno.ll | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index edc481424a6d0..f812809e5e0b5 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -1866,7 +1866,8 @@ AliasResult BasicAAResult::aliasErrno(const MemoryLocation &Loc, // There cannot be any alias with errno if the given memory location is an // identified function-local object, or the size of the memory access is // larger than the integer size. - if (Loc.Size.hasValue() && Loc.Size.getValue() * 8 > TLI.getIntSize()) + if (Loc.Size.hasValue() && + Loc.Size.getValue().getKnownMinValue() * 8 > TLI.getIntSize()) return AliasResult::NoAlias; if (isIdentifiedFunctionLocal(getUnderlyingObject(Loc.Ptr))) diff --git a/llvm/test/Transforms/InstCombine/may-alias-errno.ll b/llvm/test/Transforms/InstCombine/may-alias-errno.ll index aebc8c9e15c04..40fab8024b362 100644 --- a/llvm/test/Transforms/InstCombine/may-alias-errno.ll +++ b/llvm/test/Transforms/InstCombine/may-alias-errno.ll @@ -111,6 +111,44 @@ entry: ret i32 %0 } +; sinf clobbering errno, but %p is memory accessed w/ vector size larger than errno. +; Can do constant store-to-load forwarding. +define <4 x i32> @does_not_alias_errno_vec(ptr %p, float %f) { +; CHECK-LABEL: define <4 x i32> @does_not_alias_errno_vec( +; CHECK-SAME: ptr [[P:%.*]], float [[F:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: call void @escape(ptr [[P]]) +; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[P]], align 16 +; CHECK-NEXT: [[TMP0:%.*]] = call float @sinf(float [[F]]) +; CHECK-NEXT: ret <4 x i32> zeroinitializer +; +entry: + call void @escape(ptr %p) + store <4 x i32> zeroinitializer, ptr %p + call float @sinf(float %f) + %v = load <4 x i32>, ptr %p + ret <4 x i32> %v +} + +; sinf clobbering errno, but %p is memory accessed w/ scalable vector size larger than errno. +; Can do constant store-to-load forwarding. +define @does_not_alias_errno_scalablevec(ptr %p, float %f) { +; CHECK-LABEL: define @does_not_alias_errno_scalablevec( +; CHECK-SAME: ptr [[P:%.*]], float [[F:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: call void @escape(ptr [[P]]) +; CHECK-NEXT: store zeroinitializer, ptr [[P]], align 16 +; CHECK-NEXT: [[TMP0:%.*]] = call float @sinf(float [[F]]) +; CHECK-NEXT: ret zeroinitializer +; +entry: + call void @escape(ptr %p) + store zeroinitializer, ptr %p + call float @sinf(float %f) + %v = load , ptr %p + ret %v +} + declare float @sinf(float) memory(errnomem: write) declare float @read_errno(ptr) memory(argmem: write, errnomem: read) declare void @escape(ptr %p)