diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp @@ -88,6 +88,10 @@ namespace RISCVFeatures { void validate(const Triple &TT, const FeatureBitset &FeatureBits) { + if (TT.isArch64Bit() && !FeatureBits[RISCV::Feature64Bit]) + report_fatal_error("RV64 target requires an RV64 CPU"); + if (!TT.isArch64Bit() && FeatureBits[RISCV::Feature64Bit]) + report_fatal_error("RV32 target requires an RV32 CPU"); if (TT.isArch64Bit() && FeatureBits[RISCV::FeatureRV32E]) report_fatal_error("RV32E can't be enabled for an RV64 target"); } diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp @@ -65,7 +65,7 @@ static MCSubtargetInfo *createRISCVMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { std::string CPUName = std::string(CPU); - if (CPUName.empty()) + if (CPUName.empty() || CPUName == "generic") CPUName = TT.isArch64Bit() ? "generic-rv64" : "generic-rv32"; return createRISCVMCSubtargetInfoImpl(TT, CPUName, /*TuneCPU*/ CPUName, FS); } diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp --- a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp +++ b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp @@ -53,7 +53,7 @@ bool Is64Bit = TT.isArch64Bit(); std::string CPUName = std::string(CPU); std::string TuneCPUName = std::string(TuneCPU); - if (CPUName.empty()) + if (CPUName.empty() || CPUName == "generic") CPUName = Is64Bit ? "generic-rv64" : "generic-rv32"; if (TuneCPUName.empty()) TuneCPUName = CPUName;