Skip to content

[RISCV] Address instances of redundant or suboptimally canonicalised instructions in llvm-test-suite (tracking issue) #133449

@asb

Description

@asb

This issue tracks remaining work to remove any redundant of suboptimally canonicalised instructions as found in the output of llvm-test-suite (including SPEC). None are known to be particularly high in dynamic instruction count, but as they can be removed/improved with relatively little effort and the generated code is unambiguously better, it seems worth stepping through. This scrappy script can be used for searching binaries in a directory (may be false positives). After spotting a few of these issues by eye, I thought it was probably worth being a bit more thorough (and additionally, some of them are helpful for anyone looking to minimise code size).

There are ~8k static instances in llvm-test-suite (note: hasn't been carefully checked for false positives).

Redundant operations

Suboptimally canonicalised operations

  • Reg-reg moves encoded as e.g. sh1add with rs1=zer0.
    • Produced after MachineCopyPropagation. Not compressible, while the plain mv is.
    • Likely best solved by late stage canonicalisation. This could only be done when compression is enabled, but given it's never worse than neutral, prefer to keep codegen the same for compressed vs non-compressed.
  • or rd, zero zero
    • Not compressible, want to use c.li. Also, a number of instances of this in 502.gcc_r immediately followed by bnez on the loaded value..
  • andi with rs1==zero, zext.w of zero
  • beq zero, rs2, ... and bne zero, rs2, ..
    • Should compress to c.bnez/c.beqz and print an appropriate alias
  • seqz /snez with zero oeprand
  • sll/srl/... with zero operand for rs
  • addw rd, zero, rt
    • Should be addiw for better compressibility
  • Other minor variants of the above

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions