[llvm] [DAG] SimplifyDemandedBits - limit BITCAST -> FGETSIGN fold to custom/legal scalar SimplifyDemandedBits cases (PR #189363)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 30 06:32:10 PDT 2026
https://github.com/RKSimon updated https://github.com/llvm/llvm-project/pull/189363
>From 1dfeb8af709010ffc3992ead0b40a8f443a9b399 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Mon, 30 Mar 2026 12:46:27 +0100
Subject: [PATCH] [DAG] SimplifyDemandedBits - limit BITCAST -> FGETSIGN fold
to custom/legal scalar SimplifyDemandedBits cases
All of the non-i32 zero_extend codepath is unaffected by this
Pulled out of the discussion on #189129
---
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 0b18a3a4d7493..2c8926167b6da 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -2789,20 +2789,12 @@ bool TargetLowering::SimplifyDemandedBits(
if (!TLO.LegalOperations() && !VT.isVector() && !SrcVT.isVector() &&
DemandedBits == APInt::getSignMask(Op.getValueSizeInBits()) &&
SrcVT.isFloatingPoint()) {
- bool OpVTLegal = isOperationLegalOrCustom(ISD::FGETSIGN, VT);
- bool i32Legal = isOperationLegalOrCustom(ISD::FGETSIGN, MVT::i32);
- if ((OpVTLegal || i32Legal) && VT.isSimple() && SrcVT != MVT::f16 &&
- SrcVT != MVT::f128) {
- // Cannot eliminate/lower SHL for f128 yet.
- EVT Ty = OpVTLegal ? VT : MVT::i32;
+ if (isOperationLegalOrCustom(ISD::FGETSIGN, VT)) {
// Make a FGETSIGN + SHL to move the sign bit into the appropriate
// place. We expect the SHL to be eliminated by other optimizations.
- SDValue Sign = TLO.DAG.getNode(ISD::FGETSIGN, dl, Ty, Src);
- unsigned OpVTSizeInBits = Op.getValueSizeInBits();
- if (!OpVTLegal && OpVTSizeInBits > 32)
- Sign = TLO.DAG.getNode(ISD::ZERO_EXTEND, dl, VT, Sign);
+ SDValue Sign = TLO.DAG.getNode(ISD::FGETSIGN, dl, VT, Src);
unsigned ShVal = Op.getValueSizeInBits() - 1;
- SDValue ShAmt = TLO.DAG.getConstant(ShVal, dl, VT);
+ SDValue ShAmt = TLO.DAG.getShiftAmountConstant(ShVal, VT, dl);
return TLO.CombineTo(Op,
TLO.DAG.getNode(ISD::SHL, dl, VT, Sign, ShAmt));
}
More information about the llvm-commits
mailing list