Skip to content

Commit 0996696

Browse files
authored
[BasicAA] Handle scalable vectors in new errno aliasing checks. (llvm#159248)
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.
1 parent ac1012d commit 0996696

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,8 @@ AliasResult BasicAAResult::aliasErrno(const MemoryLocation &Loc,
18661866
// There cannot be any alias with errno if the given memory location is an
18671867
// identified function-local object, or the size of the memory access is
18681868
// larger than the integer size.
1869-
if (Loc.Size.hasValue() && Loc.Size.getValue() * 8 > TLI.getIntSize())
1869+
if (Loc.Size.hasValue() &&
1870+
Loc.Size.getValue().getKnownMinValue() * 8 > TLI.getIntSize())
18701871
return AliasResult::NoAlias;
18711872

18721873
if (isIdentifiedFunctionLocal(getUnderlyingObject(Loc.Ptr)))

llvm/test/Transforms/InstCombine/may-alias-errno.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,44 @@ entry:
111111
ret i32 %0
112112
}
113113

114+
; sinf clobbering errno, but %p is memory accessed w/ vector size larger than errno.
115+
; Can do constant store-to-load forwarding.
116+
define <4 x i32> @does_not_alias_errno_vec(ptr %p, float %f) {
117+
; CHECK-LABEL: define <4 x i32> @does_not_alias_errno_vec(
118+
; CHECK-SAME: ptr [[P:%.*]], float [[F:%.*]]) {
119+
; CHECK-NEXT: [[ENTRY:.*:]]
120+
; CHECK-NEXT: call void @escape(ptr [[P]])
121+
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[P]], align 16
122+
; CHECK-NEXT: [[TMP0:%.*]] = call float @sinf(float [[F]])
123+
; CHECK-NEXT: ret <4 x i32> zeroinitializer
124+
;
125+
entry:
126+
call void @escape(ptr %p)
127+
store <4 x i32> zeroinitializer, ptr %p
128+
call float @sinf(float %f)
129+
%v = load <4 x i32>, ptr %p
130+
ret <4 x i32> %v
131+
}
132+
133+
; sinf clobbering errno, but %p is memory accessed w/ scalable vector size larger than errno.
134+
; Can do constant store-to-load forwarding.
135+
define <vscale x 4 x i32> @does_not_alias_errno_scalablevec(ptr %p, float %f) {
136+
; CHECK-LABEL: define <vscale x 4 x i32> @does_not_alias_errno_scalablevec(
137+
; CHECK-SAME: ptr [[P:%.*]], float [[F:%.*]]) {
138+
; CHECK-NEXT: [[ENTRY:.*:]]
139+
; CHECK-NEXT: call void @escape(ptr [[P]])
140+
; CHECK-NEXT: store <vscale x 4 x i32> zeroinitializer, ptr [[P]], align 16
141+
; CHECK-NEXT: [[TMP0:%.*]] = call float @sinf(float [[F]])
142+
; CHECK-NEXT: ret <vscale x 4 x i32> zeroinitializer
143+
;
144+
entry:
145+
call void @escape(ptr %p)
146+
store <vscale x 4 x i32> zeroinitializer, ptr %p
147+
call float @sinf(float %f)
148+
%v = load <vscale x 4 x i32>, ptr %p
149+
ret <vscale x 4 x i32> %v
150+
}
151+
114152
declare float @sinf(float) memory(errnomem: write)
115153
declare float @read_errno(ptr) memory(argmem: write, errnomem: read)
116154
declare void @escape(ptr %p)

0 commit comments

Comments
 (0)