[all-commits] [llvm/llvm-project] fd6799: [DAGCombine] fold (urem x, (lshr pow2, y)) -> (and...

Philip Reames via All-commits all-commits at lists.llvm.org
Wed Jul 13 08:35:26 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fd67992f9c4b811e8db7aa58d8ad53223b089c3f
      https://github.com/llvm/llvm-project/commit/fd67992f9c4b811e8db7aa58d8ad53223b089c3f
  Author: Philip Reames <preames at rivosinc.com>
  Date:   2022-07-13 (Wed, 13 Jul 2022)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    M llvm/test/CodeGen/X86/combine-urem.ll

  Log Message:
  -----------
  [DAGCombine] fold (urem x, (lshr pow2, y)) -> (and x, (add (lshr pow2, y), -1))

We have the same fold in InstCombine - though implemented via OrZero flag on isKnownToBePowerOfTwo. The reasoning here is that either a) the result of the lshr is a power-of-two, or b) we have a div-by-zero triggering UB which we can ignore.

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




More information about the All-commits mailing list