From 1a2bd44b77c2dd0c2aabf5e27e30eb17c4715832 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 11 Jul 2022 09:26:34 -0700 Subject: [PATCH] [RISCV] Make shouldConvertConstantLoadToIntImm return true unless enableUnalignedScalarMem is true. This restores the old behavior before D129402 when enableUnalignedScalarMem is false. This fixes a regression spotted by @asb. To fix this correctly, we need to consider alignment of the load we'd be replacing, but that's not possible in the current interface. --- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 9c16da946e840..066c57614e34e 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -1174,6 +1174,13 @@ bool RISCVTargetLowering::shouldConvertConstantLoadToIntImm(const APInt &Imm, if (isInt<32>(Val)) return true; + // A constant pool entry may be more aligned thant he load we're trying to + // replace. If we don't support unaligned scalar mem, prefer the constant + // pool. + // TODO: Can the caller pass down the alignment? + if (!Subtarget.enableUnalignedScalarMem()) + return true; + // Prefer to keep the load if it would require many instructions. // This uses the same threshold we use for constant pools but doesn't // check useConstantPoolForLargeInts.