[llvm] [RISCV][VLOPT] Allow propagation even when VL isn't VLMAX (PR #112228)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 08:38:13 PDT 2024
================
@@ -641,10 +641,33 @@ bool RISCVVLOptimizer::isCandidate(const MachineInstr &MI) const {
if (MI.getNumDefs() != 1)
return false;
+ // If we're not using VLMAX, then we need to be careful whether we are using
+ // TA/TU when there is a non-undef Passthru. But when we are using VLMAX, it
+ // does not matter whether we are using TA/TU with a non-undef Passthru, since
+ // there are no tail elements to be perserved.
unsigned VLOpNum = RISCVII::getVLOpNum(Desc);
const MachineOperand &VLOp = MI.getOperand(VLOpNum);
- if (!VLOp.isImm() || VLOp.getImm() != RISCV::VLMaxSentinel)
+ if (VLOp.isReg() || VLOp.getImm() != RISCV::VLMaxSentinel) {
+ // If MI has a non-undef passthru, we will not try to optimize it since
+ // that requires us to preserve tail elements according to TA/TU.
+ // Otherwise, The MI has an undef Passthru, so it doesn't matter whether we
+ // are using TA/TU.
+ bool HasPassthru = RISCVII::isFirstDefTiedToFirstUse(Desc);
+ unsigned PassthruOpIdx = MI.getNumExplicitDefs();
+ if (HasPassthru &&
+ MI.getOperand(PassthruOpIdx).getReg() != RISCV::NoRegister) {
+ LLVM_DEBUG(
+ dbgs() << " Not a candidate because it uses non-undef passthru"
+ " with non-VLMAX VL\n");
+ return false;
+ }
+ }
+
+ // If the VL is 1, then there is no need to reduce it.
+ if (VLOp.isImm() && VLOp.getImm() == 1) {
+ LLVM_DEBUG(dbgs() << " Not a candidate because VL is already 1\n");
return false;
+ }
----------------
michaelmaitland wrote:
An optimization, not needed for correctness.
https://github.com/llvm/llvm-project/pull/112228
More information about the llvm-commits
mailing list