-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
Changes from 2 commits
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc -mtriple=arm-linux-gnueabi -mcpu=arm1022e -mattr=armv5te -o - %s | FileCheck %s | ||
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. Pretty sure this would need to be +armv5te, does this print a parse warning? 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. It's quite weird as I didn't get any warning, this definitely needs to be fixed. Dropped it as turned to be not needed (gets exercized anyways). |
||
|
||
; Ensure poison-generating flags are stripped by the time a freeze operand is visited. | ||
|
||
@g_ptr = global ptr null, align 4 | ||
|
||
define ptr @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: cmp r0, #0 | ||
; CHECK-NEXT: ldr r0, .LCPI0_0 | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: bx lr | ||
; CHECK-NEXT: .p2align 2 | ||
; CHECK-NEXT: @ %bb.1: | ||
; CHECK-NEXT: .LCPI0_0: | ||
; CHECK-NEXT: .long g_ptr | ||
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 | ||
br i1 %cmpz, label %bb.end, label %bb.false | ||
|
||
bb.false: ; preds = %entry | ||
%2 = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %spec.select.fr, i1 true) | ||
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 is unused? 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. Test simplified. |
||
br label %bb.end | ||
|
||
bb.end: ; preds = %entry, %bb.false | ||
%3 = load ptr, ptr @g_ptr, align 4 | ||
ret ptr %3 | ||
} | ||
|
||
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. |
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