[llvm] [RISCV] Don't construct a subtarget for function declarations in RISCVPromoteConstant. (PR #224115)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 11:56:57 PDT 2026
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/224115
Intrinsic declarations in particular don't have a target-features attribute so the subtarget constructor may print warning like:
hard-float 'd' ABI can't be used for a target that doesn't support the D instruction set extension
This can occur in LTO builds in -mcpu is not passed to the clang driver on the LTO step. The target-machine won't have any CPU features.
>From c7dcb4206b397c8687b734af73eb242e9eb6c066 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 16 Sep 2026 11:50:43 -0700
Subject: [PATCH] [RISCV] Don't construct a subtarget for function declarations
in RISCVPromoteConstant.
Intrinsic declarations in particular don't have a target-features
attribute so the subtarget constructor may print warning like:
hard-float 'd' ABI can't be used for a target that doesn't support the D instruction set extension
This can occur in LTO builds in -mcpu is not passed to the clang
driver on the LTO step. The target-machine won't have any CPU
features.
---
llvm/lib/Target/RISCV/RISCVPromoteConstant.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/lib/Target/RISCV/RISCVPromoteConstant.cpp b/llvm/lib/Target/RISCV/RISCVPromoteConstant.cpp
index 005b1b950818c..f9d4e854400ee 100644
--- a/llvm/lib/Target/RISCV/RISCVPromoteConstant.cpp
+++ b/llvm/lib/Target/RISCV/RISCVPromoteConstant.cpp
@@ -62,6 +62,8 @@ class RISCVPromoteConstant : public ModulePass {
const TargetMachine &TM = TPC.getTM<TargetMachine>();
bool Changed = false;
for (Function &F : M) {
+ if (F.isDeclaration())
+ continue;
const RISCVSubtarget &ST = TM.getSubtarget<RISCVSubtarget>(F);
const RISCVTargetLowering *TLI = ST.getTargetLowering();
Changed |= runOnFunction(F, TLI);
More information about the llvm-commits
mailing list