diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 1f56ca17b785b..69abcd561acd1 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -19304,6 +19304,23 @@ unsigned RISCVTargetLowering::getCustomCtpopCost(EVT VT, return isCtpopFast(VT) ? 0 : 1; } +bool RISCVTargetLowering::fallBackToDAGISel(const Instruction &Inst) const { + // We don't support scalable vectors in GISel. + if (Inst.getType()->isScalableTy()) + return true; + + for (unsigned i = 0; i < Inst.getNumOperands(); ++i) + if (Inst.getOperand(i)->getType()->isScalableTy()) + return true; + + if (const AllocaInst *AI = dyn_cast(&Inst)) { + if (AI->getAllocatedType()->isScalableTy()) + return true; + } + + return false; +} + namespace llvm::RISCVVIntrinsicsTable { #define GET_RISCVVIntrinsicsTable_IMPL diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.h b/llvm/lib/Target/RISCV/RISCVISelLowering.h index 2675b0ce43e43..e13b92be6dbdd 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.h +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.h @@ -800,6 +800,8 @@ class RISCVTargetLowering : public TargetLowering { unsigned getMaxSupportedInterleaveFactor() const override { return 8; } + bool fallBackToDAGISel(const Instruction &Inst) const override; + bool lowerInterleavedLoad(LoadInst *LI, ArrayRef Shuffles, ArrayRef Indices, diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/fallback.ll b/llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/fallback.ll new file mode 100644 index 0000000000000..5dd62de8a6bc4 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/fallback.ll @@ -0,0 +1,44 @@ +; RUN: llc -mtriple=riscv64 -mattr='+v' -O0 -global-isel -global-isel-abort=2 -pass-remarks-missed='gisel*' -verify-machineinstrs %s -o %t.out 2> %t.err +; RUN: FileCheck %s --check-prefix=FALLBACK-WITH-REPORT-OUT < %t.out +; RUN: FileCheck %s --check-prefix=FALLBACK-WITH-REPORT-ERR < %t.err + + +declare @llvm.riscv.vadd.nxv1i8.nxv1i8( + , + , + , + i64) + +; FALLBACK-WITH-REPORT-ERR: remark: :0:0: unable to lower arguments{{.*}}scalable_arg +; FALLBACK-WITH-REPORT-OUT-LABEL: scalable_arg +define @scalable_arg( %0, %1, i64 %2) nounwind { +entry: + %a = call @llvm.riscv.vadd.nxv1i8.nxv1i8( + undef, + %0, + %1, + i64 %2) + + ret %a +} + +; FALLBACK-WITH-REPORT-ERR: remark: :0:0: unable to translate instruction{{.*}}scalable_inst +; FALLBACK-WITH-REPORT-OUT-LABEL: scalable_inst +define @scalable_inst(i64 %0) nounwind { +entry: + %a = call @llvm.riscv.vadd.nxv1i8.nxv1i8( + undef, + undef, + undef, + i64 %0) + + ret %a +} + +; FALLBACK-WITH-REPORT-ERR: remark: :0:0: unable to translate instruction{{.*}}scalable_alloca +; FALLBACK-WITH-REPORT-OUT-LABEL: scalable_alloca +define void @scalable_alloca() #1 { + %local0 = alloca + load volatile , ptr %local0 + ret void +}