-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
…SCEVWrapPredicate::implies
@llvm/pr-subscribers-llvm-analysis Author: Vikram Hegde (vikramRH) ChangesThis is an attempt to fix a crash as seen here, https://godbolt.org/z/dqYzK17bj. I'm not sure if this is too conservative/right way to handle this. would just comparing and rejecting the address sizes of different address spaces be enough ? Full diff: https://github.com/llvm/llvm-project/pull/137935.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 6055c3d791cb2..b39662ef90c05 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -14967,6 +14967,12 @@ bool SCEVWrapPredicate::implies(const SCEVPredicate *N,
if (Start->getType()->isPointerTy() != OpStart->getType()->isPointerTy())
return false;
+ if (Start->getType()->isPointerTy()) {
+ if (Start->getType()->getPointerAddressSpace() !=
+ OpStart->getType()->getPointerAddressSpace())
+ return false;
+ }
+
const SCEV *Step = AR->getStepRecurrence(SE);
const SCEV *OpStep = Op->AR->getStepRecurrence(SE);
if (!SE.isKnownPositive(Step) || !SE.isKnownPositive(OpStep))
diff --git a/llvm/test/Analysis/LoopAccessAnalysis/nusw-predicates.ll b/llvm/test/Analysis/LoopAccessAnalysis/nusw-predicates.ll
index d4f7f82a8cff1..ab40a22a3274d 100644
--- a/llvm/test/Analysis/LoopAccessAnalysis/nusw-predicates.ll
+++ b/llvm/test/Analysis/LoopAccessAnalysis/nusw-predicates.ll
@@ -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'
@@ -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
+ }
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I think bailout out on different address spaces is fine.
if (Start->getType()->getPointerAddressSpace() != | ||
OpStart->getType()->getPointerAddressSpace()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Start->getType()->getPointerAddressSpace() != | |
OpStart->getType()->getPointerAddressSpace()) | |
if (Start->getType() != OpStart->getType()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
@@ -14967,6 +14967,9 @@ bool SCEVWrapPredicate::implies(const SCEVPredicate *N, | |||
if (Start->getType()->isPointerTy() != OpStart->getType()->isPointerTy()) | |||
return false; | |||
|
|||
if (Start->getType()->isPointerTy() && Start->getType() != OpStart->getType()) |
There was a problem hiding this comment.
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?
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/19268 Here is the relevant piece of the build log for the reference
|
…SCEVWrapPredicate::implies (llvm#137935)
…SCEVWrapPredicate::implies (llvm#137935)
…SCEVWrapPredicate::implies (llvm#137935)
…SCEVWrapPredicate::implies (llvm#137935)
…SCEVWrapPredicate::implies (llvm#137935)
This is an attempt to fix a crash as seen here, https://godbolt.org/z/dqYzK17bj. I'm not sure if this is too conservative/right way to handle this. would just comparing and rejecting the address sizes of different address spaces be enough ?