-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Do not treat llvm.fake.use as a debug instruction #128684
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
67 changes: 67 additions & 0 deletions
67
llvm/test/Transforms/SimplifyCFG/X86/fake-use-considered-when-sinking.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,67 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt -p="simplifycfg<sink-common-insts>" -S < %s | FileCheck %s | ||
|
|
||
| ;; Verify that fake uses are not ignored when sinking instructions in | ||
| ;; SimplifyCFG; when a fake use appears in only one incoming block they prevent | ||
| ;; further sinking, and when identical fake uses appear on both sides they | ||
| ;; are sunk normally. | ||
|
|
||
| target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" | ||
| target triple = "x86_64-unknown-linux-gnu" | ||
|
|
||
| define void @foo(i1 %bool, ptr %p) { | ||
| ; CHECK-LABEL: define void @foo( | ||
| ; CHECK-SAME: i1 [[BOOL:%.*]], ptr [[P:%.*]]) { | ||
| ; CHECK-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-NEXT: br i1 [[BOOL]], label %[[IF_ELSE:.*]], label %[[IF_THEN:.*]] | ||
| ; CHECK: [[COMMON_RET:.*]]: | ||
| ; CHECK-NEXT: ret void | ||
| ; CHECK: [[IF_THEN]]: | ||
| ; CHECK-NEXT: store ptr [[P]], ptr [[P]], align 8 | ||
| ; CHECK-NEXT: br label %[[COMMON_RET]] | ||
| ; CHECK: [[IF_ELSE]]: | ||
| ; CHECK-NEXT: store ptr [[P]], ptr [[P]], align 8 | ||
| ; CHECK-NEXT: notail call void (...) @llvm.fake.use(ptr [[P]]) | ||
| ; CHECK-NEXT: br label %[[COMMON_RET]] | ||
| ; | ||
| entry: | ||
| br i1 %bool, label %if.else, label %if.then | ||
|
|
||
| common.ret: ; preds = %if.else, %if.then | ||
| ret void | ||
|
|
||
| if.then: ; preds = %entry | ||
| store ptr %p, ptr %p, align 8 | ||
| br label %common.ret | ||
|
|
||
| if.else: ; preds = %entry | ||
| store ptr %p, ptr %p, align 8 | ||
| notail call void (...) @llvm.fake.use(ptr %p) | ||
| br label %common.ret | ||
| } | ||
|
|
||
| define void @bar(i1 %bool, ptr %p) { | ||
| ; CHECK-LABEL: define void @bar( | ||
| ; CHECK-SAME: i1 [[BOOL:%.*]], ptr [[P:%.*]]) { | ||
| ; CHECK-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-NEXT: store ptr [[P]], ptr [[P]], align 8 | ||
| ; CHECK-NEXT: notail call void (...) @llvm.fake.use(ptr [[P]]) | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| entry: | ||
| br i1 %bool, label %if.else, label %if.then | ||
|
|
||
| common.ret: ; preds = %if.else, %if.then | ||
| ret void | ||
|
|
||
| if.then: ; preds = %entry | ||
| store ptr %p, ptr %p, align 8 | ||
| notail call void (...) @llvm.fake.use(ptr %p) | ||
| br label %common.ret | ||
|
|
||
| if.else: ; preds = %entry | ||
| store ptr %p, ptr %p, align 8 | ||
| notail call void (...) @llvm.fake.use(ptr %p) | ||
| br label %common.ret | ||
| } | ||
|
|
||
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.
Seems a bit fuzzy to me whether fake.use should block this optimisation or ignore the intrinsics and sink them into the suc. I don't find the docs particularly clarifying for this specific case.
You've been close to this work and have upstreamed it, so this is less me contesting the correct behaviour, more hoping for a bit more of rationale/explanation?
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.
The basic reason here is that fake uses must be treated as any other instruction by default. As an optimization we can create specific exceptions for fake uses in cases where we know it's either safe or beneficial to treat them differently, but we wouldn't want to do so "generally" as we do by skipping them in
getPrevNonDebugInstruction.For sinking common instructions specifically, I imagine it's safe to sink fake uses separate to the other instructions in their block, but that specialization should exist in the sinking code (and would be beyond the scope of this patch).