diff --git a/clang/test/CodeGen/RISCV/rvv-intrinsics/maskedoff-undefined.c b/clang/test/CodeGen/RISCV/rvv-intrinsics/maskedoff-undefined.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/RISCV/rvv-intrinsics/maskedoff-undefined.c @@ -0,0 +1,16 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// REQUIRES: riscv-registered-target +// RUN: %clang_cc1 -triple riscv64 -target-feature +experimental-v \ +// RUN: -disable-O0-optnone -emit-llvm %s -o - | opt -S -mem2reg \ +// RUN: | FileCheck --check-prefix=CHECK-RV64 %s + +#include + +// CHECK-RV64-LABEL: @test_vadd_vv_i8m1_m( +// CHECK-RV64-NEXT: entry: +// CHECK-RV64-NEXT: [[TMP0:%.*]] = call @llvm.riscv.vadd.mask.nxv8i8.nxv8i8.i64( undef, [[OP1:%.*]], [[OP2:%.*]], [[MASK:%.*]], i64 [[VL:%.*]]) +// CHECK-RV64-NEXT: ret [[TMP0]] +// +vint8m1_t test_vadd_vv_i8m1_m (vbool8_t mask, vint8m1_t op1, vint8m1_t op2, size_t vl) { + return vadd_vv_i8m1_m(mask, vundefined_i8m1(), op1, op2, vl); +} diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp --- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp +++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp @@ -377,16 +377,25 @@ // despite having a tied def. bool ForceTailAgnostic = RISCVII::doesForceTailAgnostic(TSFlags); bool TailAgnostic = true; + // Default to mask agnostic unless the operation is masked and the destination + // is tied to a source. If the source is undef, keep it as mask agnostic. + bool MaskAgnostic = true; unsigned UseOpIdx; - if (!ForceTailAgnostic && MI.isRegTiedToUseOperand(0, &UseOpIdx)) { - TailAgnostic = false; - // If the tied operand is an IMPLICIT_DEF we can keep TailAgnostic. + if (MI.isRegTiedToUseOperand(0, &UseOpIdx)) { + // hasDummyMaskOp(TSFlags) == true means it is a non-masked instruction. + MaskAgnostic = RISCVII::hasDummyMaskOp(TSFlags); + if (!ForceTailAgnostic) + TailAgnostic = false; + // If the tied operand is an IMPLICIT_DEF we can keep MaskAgnostic and + // TailAgnostic. const MachineOperand &UseMO = MI.getOperand(UseOpIdx); MachineInstr *UseMI = MRI->getVRegDef(UseMO.getReg()); if (UseMI) { UseMI = elideCopies(UseMI, MRI); - if (UseMI && UseMI->isImplicitDef()) + if (UseMI && UseMI->isImplicitDef()) { + MaskAgnostic = true; TailAgnostic = true; + } } } @@ -398,8 +407,7 @@ InstrInfo.setAVLReg(VLOp.getReg()); } else InstrInfo.setAVLReg(RISCV::NoRegister); - InstrInfo.setVTYPE(VLMul, SEW, /*TailAgnostic*/ TailAgnostic, - /*MaskAgnostic*/ false, MaskRegOp); + InstrInfo.setVTYPE(VLMul, SEW, TailAgnostic, MaskAgnostic, MaskRegOp); return InstrInfo; } diff --git a/llvm/test/CodeGen/RISCV/rvv/maskedoff-undef.ll b/llvm/test/CodeGen/RISCV/rvv/maskedoff-undef.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvv/maskedoff-undef.ll @@ -0,0 +1,27 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -verify-machineinstrs < %s \ +; RUN: | FileCheck %s + +declare @llvm.riscv.vadd.mask.nxv8i8.nxv8i8( + , + , + , + , + i64); + +define @intrinsic_vadd_maskedoff_undef( %0, %1, %2, i64 %3) nounwind { +; CHECK-LABEL: intrinsic_vadd_maskedoff_undef: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e8, m1, ta, ma +; CHECK-NEXT: vadd.vv v8, v8, v9, v0.t +; CHECK-NEXT: jalr zero, 0(ra) +entry: + %a = call @llvm.riscv.vadd.mask.nxv8i8.nxv8i8( + undef, + %0, + %1, + %2, + i64 %3) + + ret %a +}