diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index 056f4f41ffca7..05a7e195e95ba 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -2597,6 +2597,10 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID, return translateExtractVector(CI, MIRBuilder); case Intrinsic::vector_insert: return translateInsertVector(CI, MIRBuilder); + case Intrinsic::stepvector: { + MIRBuilder.buildStepVector(getOrCreateVReg(CI), 1); + return true; + } case Intrinsic::prefetch: { Value *Addr = CI.getOperand(0); unsigned RW = cast(CI.getOperand(1))->getZExtValue(); diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp index c5e5c926160e2..d910e33ac40f6 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -811,8 +811,9 @@ MachineInstrBuilder MachineIRBuilder::buildInsert(const DstOp &Res, MachineInstrBuilder MachineIRBuilder::buildStepVector(const DstOp &Res, unsigned Step) { - ConstantInt *CI = - ConstantInt::get(getMF().getFunction().getContext(), APInt(64, Step)); + unsigned Bitwidth = Res.getLLTTy(*getMRI()).getElementType().getSizeInBits(); + ConstantInt *CI = ConstantInt::get(getMF().getFunction().getContext(), + APInt(Bitwidth, Step)); auto StepVector = buildInstr(TargetOpcode::G_STEP_VECTOR); StepVector->setDebugLoc(DebugLoc()); Res.addDefToMIB(*getMRI(), StepVector); diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stepvector.ll b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stepvector.ll new file mode 100644 index 0000000000000..08a1ac3135bd2 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stepvector.ll @@ -0,0 +1,46 @@ +; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +; RUN: llc -O0 -mtriple=aarch64-linux-gnu -mattr=+sve -global-isel -aarch64-enable-gisel-sve=1 -stop-after=irtranslator %s -o - | FileCheck %s + +define @call_step_vector_i64() { + ; CHECK-LABEL: name: call_step_vector_i64 + ; CHECK: bb.1.entry: + ; CHECK-NEXT: [[STEP_VECTOR:%[0-9]+]]:_() = G_STEP_VECTOR i64 1 + ; CHECK-NEXT: $z0 = COPY [[STEP_VECTOR]]() + ; CHECK-NEXT: RET_ReallyLR implicit $z0 +entry: + %steps = call @llvm.stepvector.nxv2i64() + ret %steps +} + +define @call_step_vector_i32() { + ; CHECK-LABEL: name: call_step_vector_i32 + ; CHECK: bb.1.entry: + ; CHECK-NEXT: [[STEP_VECTOR:%[0-9]+]]:_() = G_STEP_VECTOR i32 1 + ; CHECK-NEXT: $z0 = COPY [[STEP_VECTOR]]() + ; CHECK-NEXT: RET_ReallyLR implicit $z0 +entry: + %steps = call @llvm.stepvector.nxv4i32() + ret %steps +} + +define @call_step_vector_i16() { + ; CHECK-LABEL: name: call_step_vector_i16 + ; CHECK: bb.1.entry: + ; CHECK-NEXT: [[STEP_VECTOR:%[0-9]+]]:_() = G_STEP_VECTOR i16 1 + ; CHECK-NEXT: $z0 = COPY [[STEP_VECTOR]]() + ; CHECK-NEXT: RET_ReallyLR implicit $z0 +entry: + %steps = call @llvm.stepvector.nxv8i16() + ret %steps +} + +define @call_step_vector_i8() { + ; CHECK-LABEL: name: call_step_vector_i8 + ; CHECK: bb.1.entry: + ; CHECK-NEXT: [[STEP_VECTOR:%[0-9]+]]:_() = G_STEP_VECTOR i8 1 + ; CHECK-NEXT: $z0 = COPY [[STEP_VECTOR]]() + ; CHECK-NEXT: RET_ReallyLR implicit $z0 +entry: + %steps = call @llvm.stepvector.nxv16i8() + ret %steps +}