Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
38 changes: 38 additions & 0 deletions llvm/test/Transforms/InstCombine/may-alias-errno.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down