[PATCH] D46118: [RISCV] AsmParser support for the li pseudo instruction

Alex Bradbury via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 05:23:58 PDT 2018


asb added a comment.

Ok, there _is_ a problem using addi rather than addiw. Consider loading the immediate 0x7fffffff.

  # GCC approach:
  lui a0, 524288
  addiw a0, a0, -1
  # Approach in this pass
  lui a1, 524288
  addi a1, a1, -1

Using addiw means that the value `0x000000007fffffff` ends up in the register, but using `addi` we end up with the incorrect `0xffffffff7fffffff` in register a1.

We could probably have some logic that determines whether for a particular constant using addi is safe, but addiw seems like a safe general approach.


https://reviews.llvm.org/D46118





More information about the llvm-commits mailing list