[all-commits] [llvm/llvm-project] 56ca11: [RISCV] Add an MIR pass to replace redundant sext....

Craig Topper via All-commits all-commits at lists.llvm.org
Thu Jan 6 08:24:05 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 56ca11e31e6ad4fda6476ee65537529963a2708e
      https://github.com/llvm/llvm-project/commit/56ca11e31e6ad4fda6476ee65537529963a2708e
  Author: Craig Topper <craig.topper at sifive.com>
  Date:   2022-01-06 (Thu, 06 Jan 2022)

  Changed paths:
    M llvm/lib/Target/RISCV/CMakeLists.txt
    M llvm/lib/Target/RISCV/RISCV.h
    A llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
    M llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
    M llvm/test/CodeGen/RISCV/atomic-rmw.ll
    M llvm/test/CodeGen/RISCV/atomic-signext.ll
    M llvm/test/CodeGen/RISCV/rv64zbs.ll
    A llvm/test/CodeGen/RISCV/sextw-removal.ll
    M llvm/test/CodeGen/RISCV/split-offsets.ll

  Log Message:
  -----------
  [RISCV] Add an MIR pass to replace redundant sext.w instructions with copies.

Function calls and compare instructions tend to cause sext.w
instructions to be inserted. If we make good use of W instructions,
these operations can often end up being redundant. We don't always
detect these during SelectionDAG due to things like phis. There also
some cases caused by failure to turn extload into sextload in
SelectionDAG. extload selects to LW allowing later sext.ws to become
redundant.

This patch adds a pass that examines the input of sext.w instructions trying
to determine if it is already sign extended. Either by finding a
W instruction, other instructions that produce a sign extended result,
or looking through instructions that propagate sign bits. It uses
a worklist and visited set to search as far back as necessary.

Reviewed By: asb, kito-cheng

Differential Revision: https://reviews.llvm.org/D116397




More information about the All-commits mailing list