11 Commits

Author SHA1 Message Date
Mikael Holmen
23d4fe6c5c [RISCV] Fix gcc -Wparentheses warning [NFC]
Without this gcc warned like
 ../lib/Target/RISCV/RISCVVLOptimizer.cpp:760: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   760 |            VLOp.getReg() != RISCV::X0 && "Did not expect X0 VL");
       |
2024-10-17 08:00:31 +02:00
Michael Maitland
ae68d532f8
[RISCV][VLOPT] Allow propagation even when VL isn't VLMAX (#112228)
The original goal of this pass was to focus on vector operations with
VLMAX. However, users often utilize only part of the result, and such
usage may come from the vectorizer.

We found that relaxing this constraint can capture more optimization
opportunities, such as non-power-of-2 code generation and vector
operation sequences with different VLs.

---------

Co-authored-by: Kito Cheng <kito.cheng@sifive.com>
2024-10-16 14:58:00 -04:00
Michael Maitland
658ff0b84c
[RISCV][VLOPT] Add support for integer widening multiply instructions (#112204)
This adds support for these instructions and also tests getOperandInfo
for these instructions as well.
2024-10-16 09:37:27 -04:00
Craig Topper
f7468a2531
[RISCV][VLOpt] Correct the printing of LMUL in the debug messages. (#112413) 2024-10-15 11:57:17 -07:00
Michael Maitland
2f09c722d6 [RISCV][VLOPT][NFC] Remove section markers since riscv-isa-manual does not use them 2024-10-15 07:30:55 -07:00
Luke Lau
043f066a64
[RISCV][VLOPT] Fix operand check in isVectorOpUsedAsScalarOp (#112253)
A reduction instruction always has a passthru operand, so the scalar
operand should always be vs1 which is at index 3.

Even though the destination operand is also scalar, I think the passthru
will need to preserve all elements so I haven't included it.
2024-10-15 15:10:26 +01:00
Luke Lau
db57fc4edc
[RISCV][VLOPT] Fix passthru check in getOperandInfo (#112244)
If a pseudo has a passthru, I believe the first source operand will have
operand no 2, not 1.
2024-10-14 20:54:17 +01:00
Michael Maitland
c2c4db8d8f
[RISCV][VLOPT] Add support for 11.11 div instructions (#112201)
This adds support for these instructions and also tests getOperandInfo
for these instructions as well.
2024-10-14 14:44:33 -04:00
Michael Maitland
82e89c0271
[RISCV][VLOPT] Add support for 11.9 min/max instructions (#112198)
This adds support for these instructions and also tests getOperandInfo
for these instructions as well.
2024-10-14 14:43:56 -04:00
Jie Fu
8b17916217 [RISCV] Fix -Wunused-function in RISCVVLOptimizer.cpp (NFC)
/llvm-project/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp:125:21:
error: unused function 'operator<<' [-Werror,-Wunused-function]
static raw_ostream &operator<<(raw_ostream &OS, const OperandInfo &OI) {
                    ^
1 error generated.
2024-10-11 23:03:38 +08:00
Michael Maitland
1c94388f38
[RISCV] Introduce VLOptimizer pass (#108640)
The purpose of this optimization is to make the VL argument, for
instructions that have a VL argument, as small as possible. This is
implemented by visiting each instruction in reverse order and checking
that if it has a VL argument, whether the VL can be reduced.

By putting this pass before VSETVLI insertion, we see three kinds of
changes to generated code:
1. Eliminate VSETVLI instructions
2. Reduce the VL toggle on VSETVLI instructions that also change vtype
3. Reduce the VL set by a VSETVLI instruction

The list of supported instructions is currently whitelisted for safety.
In the future, we could add more instructions to `isSupportedInstr` to
support even more VL optimization.

We originally wrote this pass because vector GEP instructions do not
take a VL, which leads us to emit code that uses VL=VLMAX to implement
GEP in the RISC-V backend. As a result, some of the vector instructions
will write to lanes, specifically between the intended VL and VLMAX,
that will never be read. As an alternative to this pass, we considered
adding a vector predicated GEP instruction, but this would not fit well
into the intrinsic type system since GEP has a variable number of
arguments, each with arbitrary types. The second approach we considered
was to put this pass after VSETVLI insertion, but we found that it was
more difficult to recognize optimization opportunities, especially
across basic block boundaries -- the data flow analysis was also a bit
more expensive and complex.

While this pass solves the GEP problem, we have expanded it to handle
more cases of VL optimization, and there is opportunity for the analysis
to be improved to enable even more optimization. We have a few follow up
patches to post, but figured this would be a good start.

---------

Co-authored-by: Craig Topper <craig.topper@sifive.com>
Co-authored-by: Kito Cheng <kito.cheng@sifive.com>
2024-10-11 09:45:35 -04:00