[llvm] [RISCV][VLOPT] Enable the RISCVVLOptimizer by default (PR #119461)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 17 10:15:05 PST 2024


topperc wrote:

> Reading through the code, I spotted one potential correctness issue. This is a cornercase, but probably still worth fixing.
> 
> Imagine you have the following: %v = VADD_VV ... %s = VREDSUM w/ %v as scalar source %dead = VADD_VV %v, %v w/ VL=0
> 
> The last instruction is dead - it can be folded to it's passthru. (In practice, it probably will have been folded, but it's possible something could slip through to here.) However, when scaning the users of %v, we will decide that the correct VL for %v is 0 (or a register which might be zero), and reduce it below the minimum VL=1 required by the reduction.
> 
> To fix this, I believe you need to treat the CommonVL for the scalar operand case as being VL=1. You could also track a non-zero state instead.
> 
> Other than that, looks good to me. Once you've fixed this issue, happy to approve.

Should we just remove this code for now

```
    // Instructions like reductions may use a vector register as a scalar
    // register. In this case, we should treat it like a scalar register which
    // does not impact the decision on whether to optimize VL.
    if (isVectorOpUsedAsScalarOp(UserOp)) {
      [[maybe_unused]] Register R = UserOp.getReg();
      [[maybe_unused]] const TargetRegisterClass *RC = MRI->getRegClass(R);
      assert(RISCV::VRRegClass.hasSubClassEq(RC) &&
             "Expect LMUL 1 register class for vector as scalar operands!");
      LLVM_DEBUG(dbgs() << "    Use this operand as a scalar operand\n");
      continue;
    }
```

https://github.com/llvm/llvm-project/pull/119461


More information about the llvm-commits mailing list