Skip to content

Conversation

@SLTozer
Copy link
Contributor

@SLTozer SLTozer commented Jun 16, 2025

Fixes #137308.

FAKE_USE nodes in SelectionDAG currently support all applicable legalizations except for softening of float operands; this patch implements float operand softening, preventing errors when legalizing FAKE_USEs.

FAKE_USE nodes in SelectionDAG currently support all applicable
legalizations except for softening of float operands; this patch implements
float operand softening, preventing errors in legalization.
@SLTozer SLTozer self-assigned this Jun 16, 2025
@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Jun 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 16, 2025

@llvm/pr-subscribers-llvm-selectiondag

Author: Stephen Tozer (SLTozer)

Changes

Fixes #137308.

FAKE_USE nodes in SelectionDAG currently support all applicable legalizations except for softening of float operands; this patch implements float operand softening, preventing errors when legalizing FAKE_USEs.


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

3 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp (+9)
  • (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h (+1)
  • (added) llvm/test/CodeGen/AVR/intrinsics/soften-fake-use.ll (+9)
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index 7dfb43164be37..5d177b0713797 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -1113,6 +1113,9 @@ bool DAGTypeLegalizer::SoftenFloatOperand(SDNode *N, unsigned OpNo) {
 
   case ISD::BITCAST:     Res = SoftenFloatOp_BITCAST(N); break;
   case ISD::BR_CC:       Res = SoftenFloatOp_BR_CC(N); break;
+  case ISD::FAKE_USE:
+    Res = SoftenFloatOp_FAKE_USE(N);
+    break;
   case ISD::STRICT_FP_TO_FP16:
   case ISD::FP_TO_FP16:  // Same as FP_ROUND for softening purposes
   case ISD::FP_TO_BF16:
@@ -1169,6 +1172,12 @@ SDValue DAGTypeLegalizer::SoftenFloatOp_BITCAST(SDNode *N) {
   return DAG.getNode(ISD::BITCAST, SDLoc(N), N->getValueType(0), Op0);
 }
 
+SDValue DAGTypeLegalizer::SoftenFloatOp_FAKE_USE(SDNode *N) {
+  SDValue Op = GetSoftenedFloat(N->getOperand(1));
+
+  return DAG.getNode(ISD::FAKE_USE, SDLoc(N), MVT::Other, N->getOperand(0), Op);
+}
+
 SDValue DAGTypeLegalizer::SoftenFloatOp_FP_ROUND(SDNode *N) {
   // We actually deal with the partially-softened FP_TO_FP16 node too, which
   // returns an i16 so doesn't meet the constraints necessary for FP_ROUND.
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
index a541833684f38..34f716d3411fa 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
@@ -639,6 +639,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
   SDValue SoftenFloatOp_Unary(SDNode *N, RTLIB::Libcall LC);
   SDValue SoftenFloatOp_BITCAST(SDNode *N);
   SDValue SoftenFloatOp_BR_CC(SDNode *N);
+  SDValue SoftenFloatOp_FAKE_USE(SDNode *N);
   SDValue SoftenFloatOp_FP_ROUND(SDNode *N);
   SDValue SoftenFloatOp_FP_TO_XINT(SDNode *N);
   SDValue SoftenFloatOp_FP_TO_XINT_SAT(SDNode *N);
diff --git a/llvm/test/CodeGen/AVR/intrinsics/soften-fake-use.ll b/llvm/test/CodeGen/AVR/intrinsics/soften-fake-use.ll
new file mode 100644
index 0000000000000..a1fe9dbe75473
--- /dev/null
+++ b/llvm/test/CodeGen/AVR/intrinsics/soften-fake-use.ll
@@ -0,0 +1,9 @@
+; RUN: llc -O0 < %s -mtriple=avr 2>&1 --stop-after=finalize-isel | FileCheck %s
+
+;; Tests that we can soften float operands to llvm.fake.use intrinsics.
+
+define double @idd(double %d) {
+entry:
+  notail call void (...) @llvm.fake.use(double %d)
+  ret double %d
+}

@SLTozer SLTozer closed this Jun 16, 2025
@SLTozer
Copy link
Contributor Author

SLTozer commented Jun 16, 2025

Closed, as the issue has already been fixed on main.

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

Labels

llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ARM] Crash with -Og or -fextend-variable-liveness: "Do not know how to soften this operator's operand"

2 participants