[llvm] 1d1d8d6 - [RISCV] Reorder code in lowerFROUND to make the diff in D130659 cleaner. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 27 17:15:28 PDT 2022


Author: Craig Topper
Date: 2022-07-27T17:13:04-07:00
New Revision: 1d1d8d6025a26d8caa7a314b7021290a5f95188a

URL: https://github.com/llvm/llvm-project/commit/1d1d8d6025a26d8caa7a314b7021290a5f95188a
DIFF: https://github.com/llvm/llvm-project/commit/1d1d8d6025a26d8caa7a314b7021290a5f95188a.diff

LOG: [RISCV] Reorder code in lowerFROUND to make the diff in D130659 cleaner. NFC

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 7965a921ad3d..819582026032 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1888,13 +1888,28 @@ static SDValue lowerFROUND(SDValue Op, SelectionDAG &DAG) {
 
   SDLoc DL(Op);
 
+  SDValue Src = Op.getOperand(0);
+
   // Freeze the source since we are increasing the number of uses.
-  SDValue Src = DAG.getFreeze(Op.getOperand(0));
+  Src = DAG.getFreeze(Op.getOperand(0));
 
   // We do the conversion on the absolute value and fix the sign at the end.
   SDValue Abs = DAG.getNode(ISD::FABS, DL, VT, Src);
 
+  // Determine the largest integer that can be represented exactly. This and
+  // values larger than it don't have any fractional bits so don't need to
+  // be converted.
   const fltSemantics &FltSem = DAG.EVTToAPFloatSemantics(VT);
+  unsigned Precision = APFloat::semanticsPrecision(FltSem);
+  APFloat MaxVal = APFloat(FltSem);
+  MaxVal.convertFromAPInt(APInt::getOneBitSet(Precision, Precision - 1),
+                          /*IsSigned*/ false, APFloat::rmNearestTiesToEven);
+  SDValue MaxValNode = DAG.getConstantFP(MaxVal, DL, VT);
+
+  // If abs(Src) was larger than MaxVal or nan, keep it.
+  MVT SetccVT = MVT::getVectorVT(MVT::i1, VT.getVectorElementCount());
+  SDValue Mask = DAG.getSetCC(DL, SetccVT, Abs, MaxValNode, ISD::SETOLT);
+
   bool Ignored;
   APFloat Point5Pred = APFloat(0.5f);
   Point5Pred.convert(FltSem, APFloat::rmNearestTiesToEven, &Ignored);
@@ -1912,19 +1927,7 @@ static SDValue lowerFROUND(SDValue Op, SelectionDAG &DAG) {
   // Restore the original sign.
   Truncated = DAG.getNode(ISD::FCOPYSIGN, DL, VT, Truncated, Src);
 
-  // Determine the largest integer that can be represented exactly. This and
-  // values larger than it don't have any fractional bits so don't need to
-  // be converted.
-  unsigned Precision = APFloat::semanticsPrecision(FltSem);
-  APFloat MaxVal = APFloat(FltSem);
-  MaxVal.convertFromAPInt(APInt::getOneBitSet(Precision, Precision - 1),
-                          /*IsSigned*/ false, APFloat::rmNearestTiesToEven);
-  SDValue MaxValNode = DAG.getConstantFP(MaxVal, DL, VT);
-
-  // If abs(Src) was larger than MaxVal or nan, keep it.
-  MVT SetccVT = MVT::getVectorVT(MVT::i1, VT.getVectorElementCount());
-  SDValue Setcc = DAG.getSetCC(DL, SetccVT, Abs, MaxValNode, ISD::SETOLT);
-  return DAG.getSelect(DL, VT, Setcc, Truncated, Src);
+  return DAG.getSelect(DL, VT, Mask, Truncated, Src);
 }
 
 struct VIDSequence {


        


More information about the llvm-commits mailing list