[llvm] 3aa2bac - [RISCV] Use early return to simplify isFPImmLegal [nfc]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 10:44:42 PDT 2023


Author: Philip Reames
Date: 2023-10-05T10:44:11-07:00
New Revision: 3aa2bac64a2c2b0f3b61722dab4ba5a1f5c0bee5

URL: https://github.com/llvm/llvm-project/commit/3aa2bac64a2c2b0f3b61722dab4ba5a1f5c0bee5
DIFF: https://github.com/llvm/llvm-project/commit/3aa2bac64a2c2b0f3b61722dab4ba5a1f5c0bee5.diff

LOG: [RISCV] Use early return to simplify isFPImmLegal [nfc]

Minor comment and readability change only.

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 c06862d013f54ec..bd4150c87eabbd0 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -2019,14 +2019,17 @@ bool RISCVTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
     // -0.0 can be created by fmv + fneg.
     return Imm.isZero();
   }
-  // Special case: the cost for -0.0 is 1.
-  int Cost = Imm.isNegZero()
-                 ? 1
-                 : RISCVMatInt::getIntMatCost(Imm.bitcastToAPInt(),
-                                              Subtarget.getXLen(),
-                                              Subtarget.getFeatureBits());
-  // If the constantpool data is already in cache, only Cost 1 is cheaper.
-  return Cost < FPImmCost;
+
+  // Special case: fmv + fneg
+  if (Imm.isNegZero())
+    return true;
+
+  // Building an integer and then converting requires a fmv at the end of
+  // the integer sequence.
+  const int Cost =
+    1 + RISCVMatInt::getIntMatCost(Imm.bitcastToAPInt(), Subtarget.getXLen(),
+                                   Subtarget.getFeatureBits());
+  return Cost <= FPImmCost;
 }
 
 // TODO: This is very conservative.


        


More information about the llvm-commits mailing list