Skip to content

Reland "[SelectionDAG] Introducing a new ISD::POISON SDNode to represent the poison value in the IR." #135056

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 3 commits into from
Apr 10, 2025

Conversation

diggerlin
Copy link
Contributor

@diggerlin diggerlin commented Apr 9, 2025

A new ISD::POISON SDNode is introduced to represent the poison value in the IR, replacing the previous use of ISD::UNDEF

@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Apr 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 9, 2025

@llvm/pr-subscribers-backend-aarch64
@llvm/pr-subscribers-backend-powerpc

@llvm/pr-subscribers-llvm-selectiondag

Author: zhijian lin (diggerlin)

Changes

The PR fix a assert on the PR #125883


Full diff: https://github.com/llvm/llvm-project/pull/135056.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp (+1)
  • (added) llvm/test/CodeGen/RISCV/pr125883.ll (+19)
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index 5ed83060e150e..6493e0e6583f0 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -165,6 +165,7 @@ void DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) {
     case ISD::STRICT_UINT_TO_FP:
     case ISD::SINT_TO_FP:
     case ISD::UINT_TO_FP:  R = SoftenFloatRes_XINT_TO_FP(N); break;
+    case ISD::POISON:
     case ISD::UNDEF:       R = SoftenFloatRes_UNDEF(N); break;
     case ISD::VAARG:       R = SoftenFloatRes_VAARG(N); break;
     case ISD::VECREDUCE_FADD:
diff --git a/llvm/test/CodeGen/RISCV/pr125883.ll b/llvm/test/CodeGen/RISCV/pr125883.ll
new file mode 100644
index 0000000000000..f2da05c660be6
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/pr125883.ll
@@ -0,0 +1,19 @@
+; RUN: llc < %s -mtriple=riscv32  | FileCheck %s
+
+define void @b(ptr %p1)  {
+; CHECK:        .cfi_startproc
+; CHECK-NEXT: # %bb.0:                                # %entry
+; CHECK-NEXT:   sb      zero, 7(a0)
+; CHECK-NEXT:   sb      zero, 6(a0)
+; CHECK-NEXT:   sb      zero, 5(a0)
+; CHECK-NEXT:   sb      a0, 4(a0)
+; CHECK-NEXT:   sb      zero, 3(a0)
+; CHECK-NEXT:   sb      zero, 2(a0)
+; CHECK-NEXT:   sb      zero, 1(a0)
+; CHECK-NEXT:   sb      a0, 0(a0)
+; CHECK-NEXT:   ret
+
+entry:
+  store volatile double poison, ptr %p1, align 1
+  ret void
+}

@topperc
Copy link
Collaborator

topperc commented Apr 9, 2025

The title of this PR does not follow established conventions for commits in LLVM.

@diggerlin diggerlin requested review from nikic, RKSimon and amy-kwan April 9, 2025 17:44
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also fix other cases in this file? Like SoftPromoteHalfRes for example.

Done

@@ -0,0 +1,19 @@
; RUN: llc < %s -mtriple=riscv32 | FileCheck %s
Copy link
Collaborator

@RKSimon RKSimon Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect filename - prXXXXX.ll is for Problem Reports (a very old name) - which now map to issue numbers - don't use pull request numbers here

I do not think there is an issue the fix, Can I use PR125883?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diggerlin you seem to have edited Simon's message instead of replying.

You should try to give a descriptive name. Like poison-legalization.ll

@arsenm
Copy link
Contributor

arsenm commented Apr 9, 2025

Title should be what it functionally fixes

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't fix the downstream crash I reported in #125883 (comment)

@topperc
Copy link
Collaborator

topperc commented Apr 9, 2025

The reported crash came from SoftPromoteHalfResult not from SoftenFloatResult

entry:
store volatile double poison, ptr %p1, align 1
ret void
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test vector cases?

Copy link
Contributor Author

@diggerlin diggerlin Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test vector cases?

I do not think we need a vector test case, The test case has cover the code we changed.

; CHECK-NEXT: ret

entry:
store volatile double poison, ptr %p1, align 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unaligned store not necessary for the test?

@diggerlin
Copy link
Contributor Author

diggerlin commented Apr 9, 2025

This doesn't fix the downstream crash I reported in #125883 (comment)

can you give me the reproduce test case , I will add the test case into the PR.

@arichardson
Copy link
Member

This doesn't fix the downstream crash I reported in #125883 (comment)

can you give me the reproduce test case , I will add the test case into the PR.

Shouldn't that just be the same test case but with "half"?

@diggerlin diggerlin changed the title fix a assert on the PR 125883 [DAGTypeLegalize] Legalize ISD::POISON as ISD::UNDEF for Float Type Legalization Apr 9, 2025
@diggerlin diggerlin requested review from arsenm, nikic, RKSimon and kuhar April 9, 2025 19:03
@diggerlin
Copy link
Contributor Author

diggerlin commented Apr 9, 2025

This doesn't fix the downstream crash I reported in #125883 (comment)

Can you help to try it now ? @kuhar

Comment on lines 3 to 4
define void @b(ptr %p1, ptr %p2) {
; CHECK: .cfi_startproc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
define void @b(ptr %p1, ptr %p2) {
; CHECK: .cfi_startproc
define void @b(ptr %p1, ptr %p2) nounwind {

That should remove the .cfi_startproc.

Also I'd suggest one function for each type?

Copy link
Member

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using update_llc_test_checks.py (and adding nounwind to ensure it doesn't add the cfi information), otherwise this change LGTM.

But since I'm not a SelectionDAG expert please wait for someone else to approve too.

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this.

Now that the base PR is reverted, can you pull in the original change from #125883 to reland this?

@diggerlin
Copy link
Contributor Author

diggerlin commented Apr 10, 2025

Thanks for looking into this.

Now that the base PR is reverted, can you pull in the original change from #125883 to reland this?

I think we can revert your revert commit and then land the PR after the PR approved.

@kuhar
Copy link
Member

kuhar commented Apr 10, 2025

Reverting the revert would get us back into a broken state. We should reland the original PR with this fix as one commit.

…poison value in the IR. (llvm#125883)

A new ISD::POISON SDNode is introduced to represent the `poison value`
in the IR, replacing the previous use of ISD::UNDEF.
@diggerlin diggerlin changed the title [DAGTypeLegalize] Legalize ISD::POISON as ISD::UNDEF for Float Type Legalization [SelectionDAG] Introducing a new ISD::POISON SDNode to represent the poison value in the IR. Apr 10, 2025
@diggerlin
Copy link
Contributor Author

I updated the patch with the original PR (#125883) and the fix for " [DAGTypeLegalize] Legalize ISD::POISON as ISD::UNDEF for Float Type Legalization" , and change the title and summary.

@diggerlin diggerlin requested a review from kuhar April 10, 2025 14:03
Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the RISC-V crash we observed with the first version of the patch. Thanks for taking care of this!

@kuhar kuhar changed the title [SelectionDAG] Introducing a new ISD::POISON SDNode to represent the poison value in the IR. Reland "[SelectionDAG] Introducing a new ISD::POISON SDNode to represent the poison value in the IR." Apr 10, 2025
Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
@diggerlin diggerlin merged commit 378ac57 into llvm:main Apr 10, 2025
8 of 11 checks passed
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…ent the poison value in the IR." (llvm#135056)

A new ISD::POISON SDNode is introduced to represent the poison value in
the IR, replacing the previous use of ISD::UNDEF
@mstorsjo
Copy link
Member

FYI, for reference, I've bisected a very elusive and tricky crash down to this commit, when compiling with Clang on Windows/arm64. Unfortunately the crash isn't fully deterministic and seems dependent on what version of Clang I'm using to build Clang, so it's not clear cut what's the root cause. But posting here in case someone else also investigates and looks at bisects that point at this commit.

@mstorsjo
Copy link
Member

FYI, for reference, I've bisected a very elusive and tricky crash down to this commit, when compiling with Clang on Windows/arm64. Unfortunately the crash isn't fully deterministic and seems dependent on what version of Clang I'm using to build Clang, so it's not clear cut what's the root cause. But posting here in case someone else also investigates and looks at bisects that point at this commit.

Sorry for the noise; this commit was unrelated to the issue. (This commit only uncovered the bug that had been present for a couple weeks before.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants