[all-commits] [llvm/llvm-project] f65be7: [InstCombine] try to fold rem with constant divide...

RotateRight via All-commits all-commits at lists.llvm.org
Tue Dec 7 12:51:17 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f65be726ab50ff13ccafd2f134599edb33cb1e7e
      https://github.com/llvm/llvm-project/commit/f65be726ab50ff13ccafd2f134599edb33cb1e7e
  Author: Sanjay Patel <spatel at rotateright.com>
  Date:   2021-12-07 (Tue, 07 Dec 2021)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    M llvm/test/Transforms/InstCombine/rem.ll

  Log Message:
  -----------
  [InstCombine] try to fold rem with constant dividend and select-of-constants divisor

We avoid this fold in the more general cases where we use `FoldOpIntoSelect`.
That's because -- unlike most binary opcodes -- 'rem' can't usually be
speculated with a variable divisor since it can have immediate UB. But in
the case where both arms of the select are constants, we can safely evaluate
both sides and eliminate 'rem' completely.

This should fix:
https://llvm.org/PR52102

The same optimization for 'div' is planned as a follow-up patch.

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




More information about the All-commits mailing list