Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RISCV][ISel] Fold extensions when all the users can consume them
This patch allows the combines that fold extensions in binary operations to have more than one use. The approach here is pretty conservative: if all the users of an extension can fold the extension, then the folding is done, otherwise we don't fold. This is the first step towards avoiding the one-use limitation. As a result, we make a decision to fold/don't fold for a web of instructions. An instruction is part of the web of instructions as soon as it consumes an extension that needs to be folded for all its users. Because of how SDISel works a web of instructions can be visited over and over. More precisely, if the folding happens, it happens for the whole web and that's the end of it, but if the folding fails, the whole web may be revisited when another member of the web is visited. To avoid a compile time explosion in pathological cases, we bail out earlier for webs that are bigger than a given threshold (arbitrarily set at 18 for now.) This size can be changed using `--riscv-lower-ext-max-web-size=<maxWebSize>`. At the current time, I didn't see a better scheme for that. Assuming we want to stick with doing that in SDISel. Differential Revision: https://reviews.llvm.org/D133739
- Loading branch information
Showing
3 changed files
with
145 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vw-web-simplification.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=riscv32 -mattr=+v -riscv-v-vector-bits-min=128 -verify-machineinstrs %s -o - --riscv-lower-ext-max-web-size=1 | FileCheck %s --check-prefixes=NO_FOLDING | ||
; RUN: llc -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-min=128 -verify-machineinstrs %s -o - --riscv-lower-ext-max-web-size=1 | FileCheck %s --check-prefixes=NO_FOLDING | ||
; RUN: llc -mtriple=riscv32 -mattr=+v -riscv-v-vector-bits-min=128 -verify-machineinstrs %s -o - --riscv-lower-ext-max-web-size=2 | FileCheck %s --check-prefixes=NO_FOLDING | ||
; RUN: llc -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-min=128 -verify-machineinstrs %s -o - --riscv-lower-ext-max-web-size=2 | FileCheck %s --check-prefixes=NO_FOLDING | ||
; RUN: llc -mtriple=riscv32 -mattr=+v -riscv-v-vector-bits-min=128 -verify-machineinstrs %s -o - --riscv-lower-ext-max-web-size=3 | FileCheck %s --check-prefixes=FOLDING | ||
; RUN: llc -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-min=128 -verify-machineinstrs %s -o - --riscv-lower-ext-max-web-size=3 | FileCheck %s --check-prefixes=FOLDING | ||
; Check that the default value enables the web folding and | ||
; that it is bigger than 3. | ||
; RUN: llc -mtriple=riscv32 -mattr=+v -riscv-v-vector-bits-min=128 -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=FOLDING | ||
; RUN: llc -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-min=128 -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=FOLDING | ||
|
||
|
||
; Check that the add/sub/mul operations are all promoted into their | ||
; vw counterpart when the folding of the web size is increased to 3. | ||
; We need the web size to be at least 3 for the folding to happen, because | ||
; %c has 3 uses. | ||
define <2 x i16> @vwmul_v2i16_multiple_users(<2 x i8>* %x, <2 x i8>* %y, <2 x i8> *%z) { | ||
; NO_FOLDING-LABEL: vwmul_v2i16_multiple_users: | ||
; NO_FOLDING: # %bb.0: | ||
; NO_FOLDING-NEXT: vsetivli zero, 2, e16, mf4, ta, mu | ||
; NO_FOLDING-NEXT: vle8.v v8, (a0) | ||
; NO_FOLDING-NEXT: vle8.v v9, (a1) | ||
; NO_FOLDING-NEXT: vle8.v v10, (a2) | ||
; NO_FOLDING-NEXT: vsext.vf2 v11, v8 | ||
; NO_FOLDING-NEXT: vsext.vf2 v8, v9 | ||
; NO_FOLDING-NEXT: vsext.vf2 v9, v10 | ||
; NO_FOLDING-NEXT: vmul.vv v8, v11, v8 | ||
; NO_FOLDING-NEXT: vadd.vv v10, v11, v9 | ||
; NO_FOLDING-NEXT: vsub.vv v9, v11, v9 | ||
; NO_FOLDING-NEXT: vor.vv v8, v8, v10 | ||
; NO_FOLDING-NEXT: vor.vv v8, v8, v9 | ||
; NO_FOLDING-NEXT: ret | ||
; | ||
; FOLDING-LABEL: vwmul_v2i16_multiple_users: | ||
; FOLDING: # %bb.0: | ||
; FOLDING-NEXT: vsetivli zero, 2, e8, mf8, ta, mu | ||
; FOLDING-NEXT: vle8.v v8, (a0) | ||
; FOLDING-NEXT: vle8.v v9, (a1) | ||
; FOLDING-NEXT: vle8.v v10, (a2) | ||
; FOLDING-NEXT: vwmul.vv v11, v8, v9 | ||
; FOLDING-NEXT: vwadd.vv v9, v8, v10 | ||
; FOLDING-NEXT: vwsub.vv v12, v8, v10 | ||
; FOLDING-NEXT: vsetvli zero, zero, e16, mf4, ta, mu | ||
; FOLDING-NEXT: vor.vv v8, v11, v9 | ||
; FOLDING-NEXT: vor.vv v8, v8, v12 | ||
; FOLDING-NEXT: ret | ||
%a = load <2 x i8>, <2 x i8>* %x | ||
%b = load <2 x i8>, <2 x i8>* %y | ||
%b2 = load <2 x i8>, <2 x i8>* %z | ||
%c = sext <2 x i8> %a to <2 x i16> | ||
%d = sext <2 x i8> %b to <2 x i16> | ||
%d2 = sext <2 x i8> %b2 to <2 x i16> | ||
%e = mul <2 x i16> %c, %d | ||
%f = add <2 x i16> %c, %d2 | ||
%g = sub <2 x i16> %c, %d2 | ||
%h = or <2 x i16> %e, %f | ||
%i = or <2 x i16> %h, %g | ||
ret <2 x i16> %i | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters