[all-commits] [llvm/llvm-project] 373e77: [RISCV] Generalize (sub zext, zext) -> (sext (sub ...

Luke Lau via All-commits all-commits at lists.llvm.org
Sun Mar 24 22:09:18 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 373e77b4c0ad9b0bf370f0e5a32a4100a5459d82
      https://github.com/llvm/llvm-project/commit/373e77b4c0ad9b0bf370f0e5a32a4100a5459d82
  Author: Luke Lau <luke at igalia.com>
  Date:   2024-03-25 (Mon, 25 Mar 2024)

  Changed paths:
    M llvm/lib/Target/RISCV/RISCVISelLowering.cpp
    M llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vwaddu.ll
    M llvm/test/CodeGen/RISCV/rvv/vwadd-sdnode.ll

  Log Message:
  -----------
  [RISCV] Generalize (sub zext, zext) -> (sext (sub zext, zext)) to add (#86248)

This generalizes the combine added in #82455 to other binary ops,
beginning with adds in this patch.

Because the two zext operands are always +ve when treated as signed, and
we don't get any overflow since the add is carried out in at least N * 2
bits of the narrow type, the result of the add will always be +ve. So we
can use a zext for the outer extend, unlike sub which may produce a -ve
result from two +ve operands.

Although we could still use sext for add, I plan to add support for
other binary ops like mul in a later patch, but mul requires zext to be
correct (because the maximum value will take up the full N * 2 bits). So
I've opted to use zext here too for consistency.

Alive2 proof: https://alive2.llvm.org/ce/z/PRNsUM



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list