[all-commits] [llvm/llvm-project] fd5f3a: [DAG] Fold (abs (sign_extend_inreg x)) -> (zero_ex...

Simon Pilgrim via All-commits all-commits at lists.llvm.org
Mon Oct 24 02:27:23 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fd5f3abb07aa1814c7e86438a21b9f95b0e7c721
      https://github.com/llvm/llvm-project/commit/fd5f3abb07aa1814c7e86438a21b9f95b0e7c721
  Author: Simon Pilgrim <llvm-dev at redking.me.uk>
  Date:   2022-10-24 (Mon, 24 Oct 2022)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    M llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
    M llvm/test/CodeGen/X86/abs.ll

  Log Message:
  -----------
  [DAG] Fold (abs (sign_extend_inreg x)) -> (zero_extend (abs (truncate x))) (PR43370)

If the upper half of an abs() is all sign bits, then we can perform the abs() using just the lower half and then zero extend.

I've limited the DAG combine to only sign_extend_inreg (and free truncate/zero_extend) to minimise any later promotion issues, but for legalization a similar fold can use ComputeNumSignBits to be more aggressive.

Alive2: https://alive2.llvm.org/ce/z/y32fS4

Fixes #43370

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




More information about the All-commits mailing list