[PATCH] D157976: [RISCV] Use materialization cost when lowering constant build_vector

Luke Lau via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 08:20:10 PDT 2023


luke added inline comments.


================
Comment at: llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-shuffles.ll:195
 ; RV64-NEXT:    addi a0, a0, %lo(.LCPI8_0)
 ; RV64-NEXT:    vlse64.v v10, (a0), zero
 ; RV64-NEXT:    vsetivli zero, 1, e8, mf8, ta, ma
----------------
reames wrote:
> Not this change, but there's something odd here.  Unless I'm misreading this, we should be doing a splat of 2.0 as double here.  That's the hex value 0x4000000000000000 which is a constant we can materialize in two instructions at worst.  (1 with zbs).  
> 
> It looks maybe we've got a problem with how we lower constant splats of floating point types?  We should be able to use the integer mat path, and it looks like we're not doing so?
Took a look at this, this seems to be working as intended, it uses the integer mat path only if the cost to materialise the integer < 2. I.e. adding zbs gives:

```
vrgather_shuffle_vx_v4f64:              # @vrgather_shuffle_vx_v4f64
	.cfi_startproc
# %bb.0:
	vsetivli	zero, 4, e64, m2, ta, ma
	vid.v	v10
	li	a0, 3
	vmul.vx	v12, v10, a0
	bseti	a0, zero, 62
	vmv.v.x	v10, a0
	vsetivli	zero, 1, e8, mf8, ta, ma
	vmv.v.i	v0, 3
	vsetivli	zero, 4, e64, m2, ta, mu
	vrgather.vv	v10, v8, v12, v0.t
	vmv.v.v	v8, v10
	ret
```

or alternatively, increasing `-riscv-lower-fp-imm-cost` from the default 2 to 3:

```
vrgather_shuffle_vx_v4f64:              # @vrgather_shuffle_vx_v4f64
	.cfi_startproc
# %bb.0:
	vsetivli	zero, 4, e64, m2, ta, ma
	vid.v	v10
	li	a0, 3
	vmul.vx	v12, v10, a0
	li	a0, 1
	slli	a0, a0, 62
	vmv.v.x	v10, a0
	vsetivli	zero, 1, e8, mf8, ta, ma
	vmv.v.i	v0, 3
	vsetivli	zero, 4, e64, m2, ta, mu
	vrgather.vv	v10, v8, v12, v0.t
	vmv.v.v	v8, v10
	ret
```




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157976/new/

https://reviews.llvm.org/D157976



More information about the llvm-commits mailing list