[llvm] [GlobalISel][RISCV] Use constant pool for large integer constants. (PR #81101)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 12 12:41:23 PST 2024
================
@@ -451,17 +460,95 @@ bool RISCVLegalizerInfo::legalizeVAStart(MachineInstr &MI,
return true;
}
+bool RISCVLegalizerInfo::shouldBeInConstantPool(APInt APImm,
+ bool ShouldOptForSize) const {
+ unsigned BitWidth = APImm.getBitWidth();
+ assert(BitWidth == 32 || BitWidth == 64);
+ int64_t Imm = APImm.getSExtValue();
+ // All simm32 constants should be handled by isel.
+ // NOTE: The getMaxBuildIntsCost call below should return a value >= 2 making
+ // this check redundant, but small immediates are common so this check
+ // should have better compile time.
+ if (isInt<32>(Imm))
+ return false;
+
+ // We only need to cost the immediate, if constant pool lowering is enabled.
+ if (!STI.useConstantPoolForLargeInts())
+ return false;
+
+ RISCVMatInt::InstSeq Seq = RISCVMatInt::generateInstSeq(Imm, STI);
+ if (Seq.size() <= STI.getMaxBuildIntsCost())
+ return false;
+
+ // Optimizations below are disabled for opt size. If we're optimizing for
+ // size, use a constant pool.
+ if (ShouldOptForSize)
+ return true;
+ //
+ // Special case. See if we can build the constant as (ADD (SLLI X, C), X) do
----------------
topperc wrote:
We won't without other changes in the InstructionSelector. We should remove this for now.
https://github.com/llvm/llvm-project/pull/81101
More information about the llvm-commits
mailing list