-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[DA] handle memory accesses with different offsets and strides #123436
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
Changes from all commits
238bbca
164a0fa
a479bdf
9213c32
caf4f8d
468652d
108d224
c62e1f4
8dcc5a0
92f6b4f
0eae7f0
60ba4e6
8c69ebf
a80c878
bf9fcfd
3dbba8e
d9846e9
b954282
9a110df
297ff44
861ef01
4972776
338668f
869b5ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10971,6 +10971,56 @@ bool ScalarEvolution::isKnownToBeAPowerOfTwo(const SCEV *S, bool OrZero, | |
return all_of(Mul->operands(), NonRecursive) && (OrZero || isKnownNonZero(S)); | ||
} | ||
|
||
bool ScalarEvolution::isKnownMultipleOf( | ||
const SCEV *S, uint64_t M, | ||
SmallVectorImpl<const SCEVPredicate *> &Assumptions) { | ||
if (M == 0) | ||
return false; | ||
Comment on lines
+10977
to
+10978
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: What if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This function can always return false, since it is returns true of if it is a known multiple. The case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, this is exactly what I'm concerned about.
I see, that's make sense to me. |
||
if (M == 1) | ||
return true; | ||
|
||
// Recursively check AddRec operands. An AddRecExpr S is a multiple of M if S | ||
// starts with a multiple of M and at every iteration step S only adds | ||
// multiples of M. | ||
if (auto *AddRec = dyn_cast<SCEVAddRecExpr>(S)) | ||
return isKnownMultipleOf(AddRec->getStart(), M, Assumptions) && | ||
isKnownMultipleOf(AddRec->getStepRecurrence(*this), M, Assumptions); | ||
|
||
// For a constant, check that "S % M == 0". | ||
if (auto *Cst = dyn_cast<SCEVConstant>(S)) { | ||
APInt C = Cst->getAPInt(); | ||
return C.urem(M) == 0; | ||
} | ||
|
||
// TODO: Also check other SCEV expressions, i.e., SCEVAddRecExpr, etc. | ||
|
||
// Basic tests have failed. | ||
// Check "S % M == 0" at compile time and record runtime Assumptions. | ||
auto *STy = dyn_cast<IntegerType>(S->getType()); | ||
const SCEV *SmodM = | ||
getURemExpr(S, getConstant(ConstantInt::get(STy, M, false))); | ||
const SCEV *Zero = getZero(STy); | ||
|
||
// Check whether "S % M == 0" is known at compile time. | ||
if (isKnownPredicate(ICmpInst::ICMP_EQ, SmodM, Zero)) | ||
return true; | ||
|
||
// Check whether "S % M != 0" is known at compile time. | ||
if (isKnownPredicate(ICmpInst::ICMP_NE, SmodM, Zero)) | ||
return false; | ||
|
||
const SCEVPredicate *P = getComparePredicate(ICmpInst::ICMP_EQ, SmodM, Zero); | ||
|
||
// Detect redundant predicates. | ||
for (auto *A : Assumptions) | ||
if (A->implies(P, *this)) | ||
sebpop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true; | ||
|
||
// Only record non-redundant predicates. | ||
Assumptions.push_back(P); | ||
sebpop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true; | ||
} | ||
|
||
std::pair<const SCEV *, const SCEV *> | ||
ScalarEvolution::SplitIntoInitAndPostInc(const Loop *L, const SCEV *S) { | ||
// Compute SCEV on entry of loop L. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 \ | ||
; RUN: | FileCheck %s | ||
|
||
; The dependence test does not handle array accesses of different sizes: i32 and i64. | ||
; Bug 16183 - https://github.com/llvm/llvm-project/issues/16183 | ||
|
||
define i64 @bug16183_alias(ptr nocapture %A) { | ||
; CHECK-LABEL: 'bug16183_alias' | ||
; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 4 --> Dst: store i32 2, ptr %arrayidx, align 4 | ||
; CHECK-NEXT: da analyze - none! | ||
; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 4 --> Dst: %0 = load i64, ptr %A, align 8 | ||
; CHECK-NEXT: da analyze - confused! | ||
; CHECK-NEXT: Src: %0 = load i64, ptr %A, align 8 --> Dst: %0 = load i64, ptr %A, align 8 | ||
; CHECK-NEXT: da analyze - none! | ||
; | ||
entry: | ||
%arrayidx = getelementptr inbounds i32, ptr %A, i64 1 | ||
store i32 2, ptr %arrayidx, align 4 | ||
%0 = load i64, ptr %A, align 8 | ||
ret i64 %0 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.