[llvm] [InstCombine] Optimize unneeded float to int cast when icmp (PR #155501)
Artem Trokhymchuk via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 7 04:29:32 PDT 2025
================
@@ -7611,6 +7613,117 @@ Instruction *InstCombinerImpl::foldICmpCommutative(CmpPredicate Pred,
return nullptr;
}
+enum class SignType {
+ Positive,
+ NonPositive,
+ Negative,
+ NonNegative,
+};
+
+/// Check signess of a constant integer or vector of integers
+///
+/// \param C constant to check for signedness
+/// \param SignType the sign type to check against
+///
+/// \return whether constant is signess corresponds with the requesed requested
+/// sign
+static bool checkConstantSignType(const Constant *C, SignType Sign) {
+ auto CheckSign = [Sign](const APInt &Value) {
+ switch (Sign) {
+ case SignType::Positive:
+ return Value.isStrictlyPositive();
+ case SignType::NonPositive:
+ return Value.isNonPositive();
+ case SignType::Negative:
+ return Value.isNegative();
+ case SignType::NonNegative:
+ return Value.isNonNegative();
+ default:
+ llvm_unreachable("Unknown sign type");
+ }
+ };
+
+ return match(C, m_CheckedInt(CheckSign));
+}
+
+/// Cast integral constant (either scalar or vector) to an appropriate vector
+/// one
+///
+/// \param C integral contsant to cast
+/// \param FPType floating point type to cast to
+/// \param Addend addend to add before casting
+/// \param DL target data layout
+///
+/// \return result constant
+static Constant *castIntegralConstantToFloat(Constant *C, Type *FPType,
+ int Addend, const DataLayout &DL) {
+ if (!FPType->isFPOrFPVectorTy())
----------------
trokhymchuk wrote:
replaced with assert,pls take a look
https://github.com/llvm/llvm-project/pull/155501
More information about the llvm-commits
mailing list