[PATCH] D155044: [RISCV] Lower inline asm constraints vi, vj and vk.

Kito Cheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 12 00:15:16 PDT 2023


kito-cheng added a comment.

Ooops, hold on, GCC actually is accepting immediate vector value instead of immediate scalar value.

  (define_constraint "vi"
    "A vector 5-bit signed immediate."
    (and (match_code "const_vector")
         (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -16, 15)")))
  
  (define_constraint "vj"
    "A vector negated 5-bit signed immediate."
    (and (match_code "const_vector")
         (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -15, 16)")))
  
  (define_constraint "vk"
    "A vector 5-bit unsigned immediate."
    (and (match_code "const_vector")
         (match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 31)")))

I mean GCC can't really accept immediate value with either `vi`, `vk` or `vj`:

  $ cat x.c
  int foo() {
      asm volatile("## %0" :/*write*/ :/*read*/ "vi"(10): /* clobber */);
      return 0;
  }
  
  $ riscv64-unknown-linux-gnu-gcc x.c -o - -S -O3
          .file   "x.c"
          .option nopic
          .attribute arch, "rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0"
          .attribute unaligned_access, 0
          .attribute stack_align, 16
          .text
  x.c: In function 'foo':
  x.c:2:5: warning: 'asm' operand 0 probably does not match constraints
      2 |     asm volatile("## %0" :/*write*/ :/*read*/ "vi"(10): /* clobber */);
        |     ^~~
  x.c:2:5: error: impossible constraint in 'asm'
          .align  1
          .globl  foo
          .type   foo, @function
  foo:
  .LFB0:
          .cfi_startproc
          li      a0,0
          ret
          .cfi_endproc
  .LFE0:
          .size   foo, .-foo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155044



More information about the llvm-commits mailing list