-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[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 13 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,67 @@ 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
Contributor
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
Member
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
Contributor
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. | ||
sebpop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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; | ||
| } | ||
|
|
||
| // Basic tests have failed. | ||
| // Record "S % M == 0" in the runtime Assumptions. | ||
| auto recordRuntimePredicate = [&](const SCEV *S) -> void { | ||
| 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; | ||
sebpop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const SCEVPredicate *P = | ||
| getComparePredicate(ICmpInst::ICMP_EQ, SmodM, Zero); | ||
|
|
||
| // Detect redundant predicates. | ||
| for (auto *A : Assumptions) | ||
| if (A->implies(P, *this)) | ||
| return; | ||
|
|
||
| Assumptions.push_back(P); | ||
| return; | ||
| }; | ||
|
|
||
| // Expressions like "n". | ||
| if (isa<SCEVUnknown>(S)) { | ||
| recordRuntimePredicate(S); | ||
| return true; | ||
| } | ||
|
|
||
| // Expressions like "n + 1" and "n * 3". | ||
| if (isa<SCEVAddExpr>(S) || isa<SCEVMulExpr>(S)) { | ||
| if (SCEVExprContains(S, [](const SCEV *X) { return isa<SCEVUnknown>(X); })) | ||
| recordRuntimePredicate(S); | ||
| return true; | ||
sebpop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| LLVM_DEBUG(dbgs() << "SCEV node not handled yet in isKnownMultipleOf: " << *S | ||
| << "\n"); | ||
| return false; | ||
| } | ||
|
|
||
| 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 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| ; 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 with difference between array accesses | ||
| ; is not a multiple of the array element size. | ||
|
|
||
| ; In this test, the element size is i32 = 4 bytes and the difference between the | ||
| ; load and the store is 2 bytes. | ||
|
|
||
| define i32 @alias_with_different_offsets(ptr nocapture %A) { | ||
| ; CHECK-LABEL: 'alias_with_different_offsets' | ||
| ; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 1 --> Dst: store i32 2, ptr %arrayidx, align 1 | ||
| ; CHECK-NEXT: da analyze - none! | ||
| ; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 1 --> Dst: %0 = load i32, ptr %A, align 1 | ||
| ; CHECK-NEXT: da analyze - confused! | ||
| ; CHECK-NEXT: Src: %0 = load i32, ptr %A, align 1 --> Dst: %0 = load i32, ptr %A, align 1 | ||
| ; CHECK-NEXT: da analyze - none! | ||
| ; | ||
| entry: | ||
| %arrayidx = getelementptr inbounds i8, ptr %A, i64 2 | ||
| store i32 2, ptr %arrayidx, align 1 | ||
| %0 = load i32, ptr %A, align 1 | ||
| ret i32 %0 | ||
| } | ||
|
|
||
| define i32 @alias_with_parametric_offset(ptr nocapture %A, i64 %n) { | ||
| ; CHECK-LABEL: 'alias_with_parametric_offset' | ||
| ; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 1 --> Dst: store i32 2, ptr %arrayidx, align 1 | ||
| ; CHECK-NEXT: da analyze - none! | ||
| ; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 1 --> Dst: %0 = load i32, ptr %A, align 1 | ||
| ; CHECK-NEXT: da analyze - flow [|<]! | ||
| ; CHECK-NEXT: Src: %0 = load i32, ptr %A, align 1 --> Dst: %0 = load i32, ptr %A, align 1 | ||
| ; CHECK-NEXT: da analyze - none! | ||
| ; CHECK-NEXT: Runtime Assumptions: | ||
| ; CHECK-NEXT: Equal predicate: (zext i2 (trunc i64 %n to i2) to i64) == 0 | ||
| ; | ||
| entry: | ||
| %arrayidx = getelementptr inbounds i8, ptr %A, i64 %n | ||
| store i32 2, ptr %arrayidx, align 1 | ||
| %0 = load i32, ptr %A, align 1 | ||
| ret i32 %0 | ||
| } | ||
|
|
||
| define i32 @alias_with_parametric_expr(ptr nocapture %A, i64 %n, i64 %m) { | ||
| ; CHECK-LABEL: 'alias_with_parametric_expr' | ||
| ; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 1 --> Dst: store i32 2, ptr %arrayidx, align 1 | ||
| ; CHECK-NEXT: da analyze - none! | ||
| ; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 1 --> Dst: %0 = load i32, ptr %arrayidx1, align 1 | ||
| ; CHECK-NEXT: da analyze - flow [|<]! | ||
| ; CHECK-NEXT: Src: %0 = load i32, ptr %arrayidx1, align 1 --> Dst: %0 = load i32, ptr %arrayidx1, align 1 | ||
| ; CHECK-NEXT: da analyze - none! | ||
| ; CHECK-NEXT: Runtime Assumptions: | ||
| ; CHECK-NEXT: Equal predicate: (zext i2 ((trunc i64 %m to i2) + (-2 * (trunc i64 %n to i2))) to i64) == 0 | ||
| ; CHECK-NEXT: Equal predicate: (zext i2 (-2 + (trunc i64 %m to i2)) to i64) == 0 | ||
| ; | ||
| entry: | ||
| %mul = mul nsw i64 %n, 10 | ||
| %add = add nsw i64 %mul, %m | ||
| %arrayidx = getelementptr inbounds i8, ptr %A, i64 %add | ||
| store i32 2, ptr %arrayidx, align 1 | ||
|
|
||
| %add1 = add nsw i64 %m, 42 | ||
| %arrayidx1 = getelementptr inbounds i8, ptr %A, i64 %add1 | ||
| %0 = load i32, ptr %arrayidx1, align 1 | ||
| ret i32 %0 | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.