Skip to content

[SCEV] Reject comparision of pointers to different address spaces in SCEVWrapPredicate::implies #137935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2025
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
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14967,6 +14967,10 @@ bool SCEVWrapPredicate::implies(const SCEVPredicate *N,
if (Start->getType()->isPointerTy() != OpStart->getType()->isPointerTy())
return false;

// Reject pointers to different address spaces.
if (Start->getType()->isPointerTy() && Start->getType() != OpStart->getType())
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: might be worth adding a comment here to say that this rejects pointers in different address spaces?

return false;

const SCEV *Step = AR->getStepRecurrence(SE);
const SCEV *OpStep = Op->AR->getStepRecurrence(SE);
if (!SE.isKnownPositive(Step) || !SE.isKnownPositive(OpStep))
Expand Down
36 changes: 35 additions & 1 deletion llvm/test/Analysis/LoopAccessAnalysis/nusw-predicates.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes='print<access-info>' -disable-output %s 2>&1 | FileCheck %s

target datalayout = "p:16:16"
target datalayout = "p:16:16-p3:32:32"

define void @int_and_pointer_predicate(ptr %v, i32 %N) {
; CHECK-LABEL: 'int_and_pointer_predicate'
Expand Down Expand Up @@ -124,3 +124,37 @@ loop:
exit:
ret void
}

define void @pointers_to_different_aspace_predicates(ptr %v, ptr addrspace(3) %w, i32 %N) {
; CHECK-LABEL: 'pointers_to_different_aspace_predicates'
; CHECK-NEXT: loop:
; CHECK-NEXT: Report: cannot identify array bounds
; CHECK-NEXT: Dependences:
; CHECK-NEXT: Run-time memory checks:
; CHECK-NEXT: Grouped accesses:
; CHECK-EMPTY:
; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop.
; CHECK-NEXT: SCEV assumptions:
; CHECK-NEXT: {0,+,1}<%loop> Added Flags: <nusw>
; CHECK-NEXT: {%v,+,4}<%loop> Added Flags: <nusw>
; CHECK-NEXT: {%w,+,4}<%loop> Added Flags: <nusw>
; CHECK-EMPTY:
; CHECK-NEXT: Expressions re-written:
;
entry:
br label %loop

loop:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
%gep.v = getelementptr {i16, i16}, ptr %v, i64 %iv
store i16 0, ptr %gep.v, align 1
%gep.w = getelementptr i32, ptr addrspace(3) %w, i64 %iv
store i32 0, ptr addrspace(3) %gep.w, align 1
%iv.next = add i64 %iv, 1
%iv.i32 = trunc i64 %iv to i32
%.not = icmp ult i32 %N, %iv.i32
br i1 %.not, label %exit, label %loop

exit:
ret void
}