-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[DAGCombiner] Ensure poison-generating flags are stripped in freeze
op
#114582
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
Closed
antoniofrighetto
wants to merge
4
commits into
llvm:main
from
antoniofrighetto:feature/dagcombine-drop-flags
Closed
Changes from all commits
Commits
Show all changes
4 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
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,25 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc -mtriple=arm-linux-gnueabi -mcpu=arm1022e -o - %s | FileCheck %s | ||
|
||
; Ensure poison-generating flags are stripped by the time a freeze operand is visited. | ||
|
||
define i1 @drop_flags(i32 noundef %numentries, i64 %cond, i64 %arg) { | ||
; CHECK-LABEL: drop_flags: | ||
; CHECK: @ %bb.0: @ %entry | ||
; CHECK-NEXT: ldm sp, {r1, r12} | ||
; CHECK-NEXT: subs r1, r2, r1 | ||
; CHECK-NEXT: sbcs r1, r3, r12 | ||
; CHECK-NEXT: movlo r0, r2 | ||
; CHECK-NEXT: clz r0, r0 | ||
; CHECK-NEXT: lsr r0, r0, #5 | ||
; CHECK-NEXT: bx lr | ||
entry: | ||
%cmp4 = icmp samesign ult i64 %cond, %arg | ||
%conv6 = trunc nuw i64 %cond to i32 | ||
%spec.select = select i1 %cmp4, i32 %conv6, i32 %numentries | ||
%spec.select.fr = freeze i32 %spec.select | ||
%cmpz = icmp eq i32 %spec.select.fr, 0 | ||
ret i1 %cmpz | ||
} | ||
|
||
declare i32 @llvm.ctlz.i32(i32, i1) | ||
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. Unused. |
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.
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.
I don't think it is a correct fix. The following
getNode
creates a new copy without flags. However, it is CSEed to N0 inSelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, ArrayRef<SDValue> Ops, const SDNodeFlags Flags)
.We should intersect flags after CSE here:
llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Lines 10321 to 10322 in 92daad2
llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Lines 10527 to 10528 in 92daad2
I will post a fix 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.
getNode creates a copy, but
N0
is still the original node. It is indeed CSE'd, but the flag has been dropped by the time it gets CSE'd.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.
I printed the node returned by
FindNodeOrInsertPos
and gotselect_cc samesign
. The flags are not dropped. It should be fixed by #114650.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.
Quite strange. I just tried again and confirm the node returned here:
llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Lines 10321 to 10322 in 89a8c71
is
i32 = select_cc t12, t28, t16, t2, setult:ch
, immediately after visiting freeze in DAGCombiner, nullptr otherwise. I'm happy with your patch too.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.
baseline: f1e1055