[llvm] [X86] Use an FP-based expansion for v4i32 ctlz on SSE2-only targets (PR #167034)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 10 02:34:23 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/CodeGen/TargetLowering.h llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp llvm/lib/Target/X86/X86ISelLowering.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index b1aa884f5..97f026bcf 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -9481,8 +9481,8 @@ SDValue TargetLowering::expandVPCTLZ(SDNode *Node, SelectionDAG &DAG) const {
   return DAG.getNode(ISD::VP_CTPOP, dl, VT, Op, Mask, VL);
 }
 
-
-SDValue TargetLowering::expandCTLZWithFP(SDNode *Node, SelectionDAG &DAG) const {
+SDValue TargetLowering::expandCTLZWithFP(SDNode *Node,
+                                         SelectionDAG &DAG) const {
   // pseudocode :
   // if(x==0) return 32;
   // float f = (float) x;
@@ -9508,8 +9508,7 @@ SDValue TargetLowering::expandCTLZWithFP(SDNode *Node, SelectionDAG &DAG) const
     MantissaBits = APFloat::semanticsPrecision(Sem) - 1;
     ExponentBias =
         static_cast<unsigned>(-APFloat::semanticsMinExponent(Sem) + 1);
-  } 
-  else {
+  } else {
     return SDValue();
   }
 
@@ -9522,11 +9521,14 @@ SDValue TargetLowering::expandCTLZWithFP(SDNode *Node, SelectionDAG &DAG) const
   // Handling the case for Non-zero inputs using the algorithm mentioned below
   SDValue Float = DAG.getNode(ISD::UINT_TO_FP, dl, FloatVT, Op);
   SDValue FloatBits = DAG.getNode(ISD::BITCAST, dl, VT, Float);
-  SDValue Exp = DAG.getNode(ISD::SRL, dl, VT, FloatBits, DAG.getConstant(MantissaBits, dl, VT));
-  SDValue MSBIndex = DAG.getNode(ISD::SUB, dl, VT, Exp, DAG.getConstant(ExponentBias, dl, VT));
-  SDValue NonZeroRes = DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(BitWidth - 1, dl, VT), MSBIndex);
-
-  //Returns the respective DAG Node based on the input being zero or non-zero
+  SDValue Exp = DAG.getNode(ISD::SRL, dl, VT, FloatBits,
+                            DAG.getConstant(MantissaBits, dl, VT));
+  SDValue MSBIndex =
+      DAG.getNode(ISD::SUB, dl, VT, Exp, DAG.getConstant(ExponentBias, dl, VT));
+  SDValue NonZeroRes = DAG.getNode(
+      ISD::SUB, dl, VT, DAG.getConstant(BitWidth - 1, dl, VT), MSBIndex);
+
+  // Returns the respective DAG Node based on the input being zero or non-zero
   return DAG.getNode(ISD::VSELECT, dl, VT, IsZero, ZeroRes, NonZeroRes);
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/167034


More information about the llvm-commits mailing list