Skip to content

Conversation

davemgreen
Copy link
Collaborator

This is a minor fixup for scalable vectors after f9f62ef. 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.

This is a minor fixup for scalable vectors after f9f62ef. 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.
@davemgreen davemgreen requested a review from nikic as a code owner September 17, 2025 05:53
@llvmbot llvmbot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Sep 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-analysis

Author: David Green (davemgreen)

Changes

This is a minor fixup for scalable vectors after f9f62ef. 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.


Full diff: https://github.com/llvm/llvm-project/pull/159248.diff

2 Files Affected:

  • (modified) llvm/lib/Analysis/BasicAliasAnalysis.cpp (+2-1)
  • (modified) llvm/test/Transforms/InstCombine/may-alias-errno.ll (+38)
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 <vscale x 4 x i32> @does_not_alias_errno_scalablevec(ptr %p, float %f) {
+; CHECK-LABEL: define <vscale x 4 x i32> @does_not_alias_errno_scalablevec(
+; CHECK-SAME: ptr [[P:%.*]], float [[F:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    call void @escape(ptr [[P]])
+; CHECK-NEXT:    store <vscale x 4 x i32> zeroinitializer, ptr [[P]], align 16
+; CHECK-NEXT:    [[TMP0:%.*]] = call float @sinf(float [[F]])
+; CHECK-NEXT:    ret <vscale x 4 x i32> zeroinitializer
+;
+entry:
+  call void @escape(ptr %p)
+  store <vscale x 4 x i32> zeroinitializer, ptr %p
+  call float @sinf(float %f)
+  %v = load <vscale x 4 x i32>, ptr %p
+  ret <vscale x 4 x i32> %v
+}
+
 declare float @sinf(float) memory(errnomem: write)
 declare float @read_errno(ptr) memory(argmem: write, errnomem: read)
 declare void @escape(ptr %p)

Copy link
Contributor

@antoniofrighetto antoniofrighetto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@davemgreen davemgreen enabled auto-merge (squash) September 17, 2025 06:18
@davemgreen davemgreen merged commit 0996696 into llvm:main Sep 17, 2025
13 checks passed
@davemgreen
Copy link
Collaborator Author

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants