-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[LoopDist] Consider reads and writes together for runtime checks #145623
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
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
af3207b
[LoopDist] Add some runtime checks for cross partition loads
mcberg2021 7f076e0
Merge branch 'main' into users/mcberg2021_LoopDistribute
mcberg2021 ab696fb
Merge branch 'main' into users/mcberg2021_LoopDistribute
mcberg2021 0dadf65
[LoopDist] Consider reads and writes together for runtime checks
mcberg2021 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
llvm/test/Transforms/LoopDistribute/cross-partition-access.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt -aa-pipeline=basic-aa -passes=loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S %s | FileCheck %s | ||
|
|
||
| ; Test emit safety guards for ptr access of %a and %c on a cross parition load which | ||
| ; has a corresponding store to the same address. This ensures that if %a and %c | ||
| ; overlap in some scenarios, that we execute the original loop for safety reasons. | ||
|
|
||
| define dso_local void @_Z13distribution3PiS_S_S_i(ptr nocapture noundef %a, ptr nocapture noundef readonly %b, ptr nocapture noundef %c, ptr nocapture noundef writeonly %d, i64 noundef signext %len) { | ||
| ; CHECK-LABEL: define dso_local void @_Z13distribution3PiS_S_S_i( | ||
| ; CHECK-SAME: ptr noundef captures(none) [[A:%.*]], ptr noundef readonly captures(none) [[B:%.*]], ptr noundef captures(none) [[C:%.*]], ptr noundef writeonly captures(none) [[D:%.*]], i64 noundef signext [[LEN:%.*]]) { | ||
| ; CHECK-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[LEN]], 0 | ||
| ; CHECK-NEXT: br i1 [[CMP]], label %[[END:.*]], label %[[FOR_BODY_LVER_CHECK:.*]] | ||
| ; CHECK: [[FOR_BODY_LVER_CHECK]]: | ||
| ; CHECK-NEXT: [[TMP0:%.*]] = shl i64 [[LEN]], 2 | ||
| ; CHECK-NEXT: [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[A]], i64 [[TMP0]] | ||
| ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[C]], i64 -4 | ||
| ; CHECK-NEXT: [[SCEVGEP5:%.*]] = getelementptr i8, ptr [[C]], i64 [[TMP0]] | ||
| ; CHECK-NEXT: [[SCEVGEP3:%.*]] = getelementptr i8, ptr [[D]], i64 [[TMP0]] | ||
| ; CHECK-NEXT: [[SCEVGEP4:%.*]] = getelementptr i8, ptr [[B]], i64 [[TMP0]] | ||
| ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult ptr [[A]], [[SCEVGEP5]] | ||
| ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult ptr [[SCEVGEP]], [[SCEVGEP2]] | ||
| ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND1]], [[BOUND0]] | ||
| ; CHECK-NEXT: [[BOUND07:%.*]] = icmp ult ptr [[A]], [[SCEVGEP3]] | ||
| ; CHECK-NEXT: [[BOUND18:%.*]] = icmp ult ptr [[D]], [[SCEVGEP2]] | ||
| ; CHECK-NEXT: [[FOUND_CONFLICT9:%.*]] = and i1 [[BOUND07]], [[BOUND18]] | ||
| ; CHECK-NEXT: [[CONFLICT_RDX:%.*]] = or i1 [[FOUND_CONFLICT]], [[FOUND_CONFLICT9]] | ||
| ; CHECK-NEXT: [[BOUND010:%.*]] = icmp ult ptr [[A]], [[SCEVGEP4]] | ||
| ; CHECK-NEXT: [[BOUND111:%.*]] = icmp ult ptr [[B]], [[SCEVGEP2]] | ||
| ; CHECK-NEXT: [[FOUND_CONFLICT12:%.*]] = and i1 [[BOUND010]], [[BOUND111]] | ||
| ; CHECK-NEXT: [[CONFLICT_RDX13:%.*]] = or i1 [[CONFLICT_RDX]], [[FOUND_CONFLICT12]] | ||
| ; CHECK-NEXT: [[BOUND014:%.*]] = icmp ult ptr [[SCEVGEP]], [[SCEVGEP3]] | ||
| ; CHECK-NEXT: [[BOUND115:%.*]] = icmp ult ptr [[D]], [[SCEVGEP5]] | ||
| ; CHECK-NEXT: [[FOUND_CONFLICT16:%.*]] = and i1 [[BOUND014]], [[BOUND115]] | ||
| ; CHECK-NEXT: [[CONFLICT_RDX17:%.*]] = or i1 [[CONFLICT_RDX13]], [[FOUND_CONFLICT16]] | ||
| ; CHECK-NEXT: [[BOUND018:%.*]] = icmp ult ptr [[D]], [[SCEVGEP4]] | ||
| ; CHECK-NEXT: [[BOUND119:%.*]] = icmp ult ptr [[B]], [[SCEVGEP3]] | ||
| ; CHECK-NEXT: [[FOUND_CONFLICT20:%.*]] = and i1 [[BOUND018]], [[BOUND119]] | ||
| ; CHECK-NEXT: [[CONFLICT_RDX21:%.*]] = or i1 [[CONFLICT_RDX17]], [[FOUND_CONFLICT20]] | ||
| ; CHECK-NEXT: br i1 [[CONFLICT_RDX21]], label %[[FOR_BODY_PH_LVER_ORIG:.*]], label %[[FOR_BODY_PH_LDIST1:.*]] | ||
| ; CHECK: [[FOR_BODY_PH_LVER_ORIG]]: | ||
| ; CHECK-NEXT: br label %[[FOR_BODY_LVER_ORIG:.*]] | ||
| ; CHECK: [[FOR_BODY_LVER_ORIG]]: | ||
| ; CHECK-NEXT: [[IDXPROM_LVER_ORIG:%.*]] = phi i64 [ 0, %[[FOR_BODY_PH_LVER_ORIG]] ], [ [[I6_LVER_ORIG:%.*]], %[[FOR_BODY_LVER_ORIG]] ] | ||
| ; CHECK-NEXT: [[ARRAYIDX_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[IDXPROM_LVER_ORIG]] | ||
| ; CHECK-NEXT: [[I2_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDX_LVER_ORIG]], align 4, !tbaa [[TBAA0:![0-9]+]] | ||
| ; CHECK-NEXT: [[ADD4_LVER_ORIG:%.*]] = add nsw i32 [[I2_LVER_ORIG]], 1 | ||
| ; CHECK-NEXT: [[ARRAYIDX8_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IDXPROM_LVER_ORIG]] | ||
| ; CHECK-NEXT: store i32 [[ADD4_LVER_ORIG]], ptr [[ARRAYIDX8_LVER_ORIG]], align 4, !tbaa [[TBAA0]] | ||
| ; CHECK-NEXT: [[I3_LVER_ORIG:%.*]] = getelementptr i32, ptr [[C]], i64 [[IDXPROM_LVER_ORIG]] | ||
| ; CHECK-NEXT: [[ARRAYIDX17_LVER_ORIG:%.*]] = getelementptr i8, ptr [[I3_LVER_ORIG]], i64 -4 | ||
| ; CHECK-NEXT: [[I4_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDX17_LVER_ORIG]], align 4, !tbaa [[TBAA0]] | ||
| ; CHECK-NEXT: [[SUB18_LVER_ORIG:%.*]] = sub nsw i32 [[ADD4_LVER_ORIG]], [[I4_LVER_ORIG]] | ||
| ; CHECK-NEXT: store i32 [[SUB18_LVER_ORIG]], ptr [[I3_LVER_ORIG]], align 4, !tbaa [[TBAA0]] | ||
| ; CHECK-NEXT: [[I5_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDX8_LVER_ORIG]], align 4, !tbaa [[TBAA0]] | ||
| ; CHECK-NEXT: [[ADD27_LVER_ORIG:%.*]] = add nsw i32 [[I5_LVER_ORIG]], 2 | ||
| ; CHECK-NEXT: [[ARRAYIDX31_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[D]], i64 [[IDXPROM_LVER_ORIG]] | ||
| ; CHECK-NEXT: store i32 [[ADD27_LVER_ORIG]], ptr [[ARRAYIDX31_LVER_ORIG]], align 4, !tbaa [[TBAA0]] | ||
| ; CHECK-NEXT: [[I6_LVER_ORIG]] = add i64 [[IDXPROM_LVER_ORIG]], 1 | ||
| ; CHECK-NEXT: [[CMP1_NOT_LVER_ORIG:%.*]] = icmp eq i64 [[I6_LVER_ORIG]], [[LEN]] | ||
| ; CHECK-NEXT: br i1 [[CMP1_NOT_LVER_ORIG]], label %[[END_LOOPEXIT_LOOPEXIT:.*]], label %[[FOR_BODY_LVER_ORIG]], !llvm.loop [[LOOP4:![0-9]+]] | ||
| ; CHECK: [[FOR_BODY_PH_LDIST1]]: | ||
| ; CHECK-NEXT: br label %[[FOR_BODY_LDIST1:.*]] | ||
| ; CHECK: [[FOR_BODY_LDIST1]]: | ||
| ; CHECK-NEXT: [[IDXPROM_LDIST1:%.*]] = phi i64 [ 0, %[[FOR_BODY_PH_LDIST1]] ], [ [[I6_LDIST1:%.*]], %[[FOR_BODY_LDIST1]] ] | ||
| ; CHECK-NEXT: [[ARRAYIDX_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[IDXPROM_LDIST1]] | ||
| ; CHECK-NEXT: [[I2_LDIST1:%.*]] = load i32, ptr [[ARRAYIDX_LDIST1]], align 4, !tbaa [[TBAA0]], !alias.scope [[META6:![0-9]+]] | ||
| ; CHECK-NEXT: [[ADD4_LDIST1:%.*]] = add nsw i32 [[I2_LDIST1]], 1 | ||
| ; CHECK-NEXT: [[ARRAYIDX8_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IDXPROM_LDIST1]] | ||
| ; CHECK-NEXT: store i32 [[ADD4_LDIST1]], ptr [[ARRAYIDX8_LDIST1]], align 4, !tbaa [[TBAA0]], !alias.scope [[META9:![0-9]+]], !noalias [[META11:![0-9]+]] | ||
| ; CHECK-NEXT: [[I3_LDIST1:%.*]] = getelementptr i32, ptr [[C]], i64 [[IDXPROM_LDIST1]] | ||
| ; CHECK-NEXT: [[ARRAYIDX17_LDIST1:%.*]] = getelementptr i8, ptr [[I3_LDIST1]], i64 -4 | ||
| ; CHECK-NEXT: [[I4_LDIST1:%.*]] = load i32, ptr [[ARRAYIDX17_LDIST1]], align 4, !tbaa [[TBAA0]], !alias.scope [[META14:![0-9]+]], !noalias [[META15:![0-9]+]] | ||
| ; CHECK-NEXT: [[SUB18_LDIST1:%.*]] = sub nsw i32 [[ADD4_LDIST1]], [[I4_LDIST1]] | ||
| ; CHECK-NEXT: store i32 [[SUB18_LDIST1]], ptr [[I3_LDIST1]], align 4, !tbaa [[TBAA0]], !alias.scope [[META14]], !noalias [[META15]] | ||
| ; CHECK-NEXT: [[I6_LDIST1]] = add i64 [[IDXPROM_LDIST1]], 1 | ||
| ; CHECK-NEXT: [[CMP1_NOT_LDIST1:%.*]] = icmp eq i64 [[I6_LDIST1]], [[LEN]] | ||
| ; CHECK-NEXT: br i1 [[CMP1_NOT_LDIST1]], label %[[FOR_BODY_PH:.*]], label %[[FOR_BODY_LDIST1]], !llvm.loop [[LOOP16:![0-9]+]] | ||
| ; CHECK: [[FOR_BODY_PH]]: | ||
| ; CHECK-NEXT: br label %[[FOR_BODY:.*]] | ||
| ; CHECK: [[FOR_BODY]]: | ||
| ; CHECK-NEXT: [[IDXPROM:%.*]] = phi i64 [ 0, %[[FOR_BODY_PH]] ], [ [[I6:%.*]], %[[FOR_BODY]] ] | ||
| ; CHECK-NEXT: [[ARRAYIDX8:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IDXPROM]] | ||
| ; CHECK-NEXT: [[I5:%.*]] = load i32, ptr [[ARRAYIDX8]], align 4, !tbaa [[TBAA0]], !alias.scope [[META9]], !noalias [[META11]] | ||
| ; CHECK-NEXT: [[ADD27:%.*]] = add nsw i32 [[I5]], 2 | ||
| ; CHECK-NEXT: [[ARRAYIDX31:%.*]] = getelementptr inbounds i32, ptr [[D]], i64 [[IDXPROM]] | ||
| ; CHECK-NEXT: store i32 [[ADD27]], ptr [[ARRAYIDX31]], align 4, !tbaa [[TBAA0]], !alias.scope [[META15]], !noalias [[META6]] | ||
| ; CHECK-NEXT: [[I6]] = add i64 [[IDXPROM]], 1 | ||
| ; CHECK-NEXT: [[CMP1_NOT:%.*]] = icmp eq i64 [[I6]], [[LEN]] | ||
| ; CHECK-NEXT: br i1 [[CMP1_NOT]], label %[[END_LOOPEXIT_LOOPEXIT20:.*]], label %[[FOR_BODY]], !llvm.loop [[LOOP16]] | ||
| ; CHECK: [[END_LOOPEXIT_LOOPEXIT]]: | ||
| ; CHECK-NEXT: br label %[[END_LOOPEXIT:.*]] | ||
| ; CHECK: [[END_LOOPEXIT_LOOPEXIT20]]: | ||
| ; CHECK-NEXT: br label %[[END_LOOPEXIT]] | ||
| ; CHECK: [[END_LOOPEXIT]]: | ||
| ; CHECK-NEXT: br label %[[END]] | ||
| ; CHECK: [[END]]: | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| entry: | ||
| %cmp = icmp sgt i64 %len, 0 | ||
| br i1 %cmp, label %end, label %for.body.preheader | ||
|
|
||
| for.body.preheader: ; preds = %entry | ||
| br label %for.body | ||
|
|
||
| for.body: ; preds = %for.body, %for.body.preheader | ||
| %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] | ||
| %arrayidx = getelementptr inbounds i32, ptr %b, i64 %indvars.iv | ||
| %i2 = load i32, ptr %arrayidx, align 4, !tbaa !0 | ||
| %add4 = add nsw i32 %i2, 1 | ||
| %arrayidx8 = getelementptr inbounds i32, ptr %a, i64 %indvars.iv | ||
| store i32 %add4, ptr %arrayidx8, align 4, !tbaa !0 | ||
| %i3 = getelementptr i32, ptr %c, i64 %indvars.iv | ||
| %arrayidx17 = getelementptr i8, ptr %i3, i64 -4 | ||
| %i4 = load i32, ptr %arrayidx17, align 4, !tbaa !0 | ||
| %sub18 = sub nsw i32 %add4, %i4 | ||
| store i32 %sub18, ptr %i3, align 4, !tbaa !0 | ||
| %i5 = load i32, ptr %arrayidx8, align 4, !tbaa !0 | ||
| %add27 = add nsw i32 %i5, 2 | ||
| %arrayidx31 = getelementptr inbounds i32, ptr %d, i64 %indvars.iv | ||
| store i32 %add27, ptr %arrayidx31, align 4, !tbaa !0 | ||
| %indvars.iv.next = add i64 %indvars.iv, 1 | ||
| %cmp1.not = icmp eq i64 %indvars.iv.next, %len | ||
| br i1 %cmp1.not, label %end.loopexit, label %for.body, !llvm.loop !4 | ||
|
|
||
| end.loopexit: ; preds = %for.body | ||
| br label %end | ||
|
|
||
| end: ; preds = %end.loopexit, %entry | ||
| ret void | ||
| } | ||
|
|
||
| !0 = !{!1, !1, i64 0} | ||
| !1 = !{!"int", !2, i64 0} | ||
| !2 = !{!"omnipotent char", !3, i64 0} | ||
| !3 = !{!"Simple C++ TBAA"} | ||
| !4 = distinct !{!4, !5} | ||
| !5 = !{!"llvm.loop.mustprogress"} | ||
|
|
||
| ;. | ||
| ; CHECK: [[TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0} | ||
| ; CHECK: [[META1]] = !{!"int", [[META2:![0-9]+]], i64 0} | ||
| ; CHECK: [[META2]] = !{!"omnipotent char", [[META3:![0-9]+]], i64 0} | ||
| ; CHECK: [[META3]] = !{!"Simple C++ TBAA"} | ||
| ; CHECK: [[LOOP4]] = distinct !{[[LOOP4]], [[META5:![0-9]+]]} | ||
| ; CHECK: [[META5]] = !{!"llvm.loop.mustprogress"} | ||
| ; CHECK: [[META6]] = !{[[META7:![0-9]+]]} | ||
| ; CHECK: [[META7]] = distinct !{[[META7]], [[META8:![0-9]+]]} | ||
| ; CHECK: [[META8]] = distinct !{[[META8]], !"LVerDomain"} | ||
| ; CHECK: [[META9]] = !{[[META10:![0-9]+]]} | ||
| ; CHECK: [[META10]] = distinct !{[[META10]], [[META8]]} | ||
| ; CHECK: [[META11]] = !{[[META12:![0-9]+]], [[META13:![0-9]+]], [[META7]]} | ||
| ; CHECK: [[META12]] = distinct !{[[META12]], [[META8]]} | ||
| ; CHECK: [[META13]] = distinct !{[[META13]], [[META8]]} | ||
| ; CHECK: [[META14]] = !{[[META12]]} | ||
| ; CHECK: [[META15]] = !{[[META13]]} | ||
| ; CHECK: [[LOOP16]] = distinct !{[[LOOP16]], [[META5]]} | ||
| ;. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm, do we ensure we also handle cases where
Ptris used by loads with another pointer-op in between?Uh oh!
There was an error while loading. Please reload this page.
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.
Once we have Ptr belonging multiple partitions, any other pointer-op should be detected by the check generation code which emits all the checks for overlapping pointers.
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.
There are other instructions other than LoadInst that only read from memory, such as calls marked with
ModRefInfo::Ref. I think this should useLAI.getInstructionsForAccess(Ptr, false)as the code above, best even integrated with the code above: IfRtPtrCheck->Pointers[I].IsWritePtris true, compareLAI.getInstructionsForAccess(Ptr, false)andLAI.getInstructionsForAccess(Ptr, true)