Skip to content

Commit c49761c

Browse files
committed
[SelectionDAG] Enable softening of FAKE_USE float operands
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.
1 parent 1bd4f97 commit c49761c

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,9 @@ bool DAGTypeLegalizer::SoftenFloatOperand(SDNode *N, unsigned OpNo) {
11131113

11141114
case ISD::BITCAST: Res = SoftenFloatOp_BITCAST(N); break;
11151115
case ISD::BR_CC: Res = SoftenFloatOp_BR_CC(N); break;
1116+
case ISD::FAKE_USE:
1117+
Res = SoftenFloatOp_FAKE_USE(N);
1118+
break;
11161119
case ISD::STRICT_FP_TO_FP16:
11171120
case ISD::FP_TO_FP16: // Same as FP_ROUND for softening purposes
11181121
case ISD::FP_TO_BF16:
@@ -1169,6 +1172,12 @@ SDValue DAGTypeLegalizer::SoftenFloatOp_BITCAST(SDNode *N) {
11691172
return DAG.getNode(ISD::BITCAST, SDLoc(N), N->getValueType(0), Op0);
11701173
}
11711174

1175+
SDValue DAGTypeLegalizer::SoftenFloatOp_FAKE_USE(SDNode *N) {
1176+
SDValue Op = GetSoftenedFloat(N->getOperand(1));
1177+
1178+
return DAG.getNode(ISD::FAKE_USE, SDLoc(N), MVT::Other, N->getOperand(0), Op);
1179+
}
1180+
11721181
SDValue DAGTypeLegalizer::SoftenFloatOp_FP_ROUND(SDNode *N) {
11731182
// We actually deal with the partially-softened FP_TO_FP16 node too, which
11741183
// returns an i16 so doesn't meet the constraints necessary for FP_ROUND.

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
639639
SDValue SoftenFloatOp_Unary(SDNode *N, RTLIB::Libcall LC);
640640
SDValue SoftenFloatOp_BITCAST(SDNode *N);
641641
SDValue SoftenFloatOp_BR_CC(SDNode *N);
642+
SDValue SoftenFloatOp_FAKE_USE(SDNode *N);
642643
SDValue SoftenFloatOp_FP_ROUND(SDNode *N);
643644
SDValue SoftenFloatOp_FP_TO_XINT(SDNode *N);
644645
SDValue SoftenFloatOp_FP_TO_XINT_SAT(SDNode *N);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: llc -O0 < %s -mtriple=avr 2>&1 --stop-after=finalize-isel | FileCheck %s
2+
3+
;; Tests that we can soften float operands to llvm.fake.use intrinsics.
4+
5+
define double @idd(double %d) {
6+
entry:
7+
notail call void (...) @llvm.fake.use(double %d)
8+
ret double %d
9+
}

0 commit comments

Comments
 (0)