llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.14k stars 12.02k forks source link

[RISCV] Fatal error when increasing minimum VLEN via target attribute #76703

Open lukel97 opened 10 months ago

lukel97 commented 10 months ago

Trying to use a target attribute to increase the minimum VLEN results in a fatal error, e.g. the below with clang -march=rv64gv:

__attribute__((target("arch=+zvl256b")))
int f() { return 42; }

results in:

fatal error: error in backend: riscv-v-vector-bits-min specified is lower than the Zvl*b limitation

riscv-v-vector-bits-min is computed from vscale_range:

; Function Attrs: noinline nounwind optnone vscale_range(2,1024)
define dso_local signext i32 @f() #0 {
entry:
  ret i32 42
}
attributes #0 = { noinline nounwind optnone vscale_range(2,1024) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic-rv64" "target-features"="+64bit,+a,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-c,-e,-experimental-zacas,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zicond,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-smaia,-ssaia,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zicbom,-zicbop,-zicboz,-zicntr,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvbb,-zvbc,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b" }

I think it should have been initialized to vscale_range(4, 1024) here based off of the target attribute.

llvmbot commented 10 months ago

@llvm/issue-subscribers-backend-risc-v

Author: Luke Lau (lukel97)

Trying to use a target attribute to increase the minimum VLEN results in a fatal error, e.g. the below with `clang -march=rv64gv`: ```c __attribute__((target("arch=+zvl256b"))) int f() { return 42; } ``` results in: ``` fatal error: error in backend: riscv-v-vector-bits-min specified is lower than the Zvl*b limitation ``` riscv-v-vector-bits-min is computed from vscale_range: ``` ; Function Attrs: noinline nounwind optnone vscale_range(2,1024) define dso_local signext i32 @f() #0 { entry: ret i32 42 } attributes #0 = { noinline nounwind optnone vscale_range(2,1024) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic-rv64" "target-features"="+64bit,+a,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-c,-e,-experimental-zacas,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zicond,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-smaia,-ssaia,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zicbom,-zicbop,-zicboz,-zicntr,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvbb,-zvbc,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b" } ``` I think it should have been initialized to vscale_range(4, 1024) here based off of the target attribute.
topperc commented 2 weeks ago

I think this stems from the frontend applying vscale_range attributes base on the command line only and not on function attributes.

We could maybe just delete this error. We should check if we have an error in the other direction, where a function has a zvl*b higher than vscale_max. That would be bad.

preames commented 2 weeks ago

I think we need to change the frontend to adjust vscale_range based on the VLEN from attributes. Otherwise, I think we somewhat defeat the purpose of the zvl256b annotation since mid-level optimizer will still assume vscale_range in the function has a minimum of 2 not 4. That's sound, but probably not what the user wanted.

topperc commented 2 weeks ago

I think we need to change the frontend to adjust vscale_range based on the VLEN from attributes. Otherwise, I think we somewhat defeat the purpose of the zvl256b annotation since mid-level optimizer will still assume vscale_range in the function has a minimum of 2 not 4. That's sound, but probably not what the user wanted.

Agreed. I'm just not sure how much work that is.