[all-commits] [llvm/llvm-project] 29fe3f: [InstSimplify] Peephole optimization for icmp (ure...

Xavier Denis via All-commits all-commits at lists.llvm.org
Tue Aug 4 11:50:17 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 29fe3fe6155fd79ce731a119ce8065a8a0d26b56
      https://github.com/llvm/llvm-project/commit/29fe3fe6155fd79ce731a119ce8065a8a0d26b56
  Author: Xavier Denis <xldenis at gmail.com>
  Date:   2020-08-04 (Tue, 04 Aug 2020)

  Changed paths:
    M llvm/lib/Analysis/InstructionSimplify.cpp
    M llvm/test/Transforms/InstSimplify/compare.ll

  Log Message:
  -----------
  [InstSimplify] Peephole optimization for icmp (urem X, Y), X

This revision adds the following peephole optimization
and it's negation:

    %a = urem i64 %x, %y
    %b = icmp ule i64 %a, %x
    ====>
    %b = true

With John Regehr's help this optimization was checked with Alive2
which suggests it should be valid.

This pattern occurs in the bound checks of Rust code, the program

    const N: usize = 3;
    const T = u8;

    pub fn split_mutiple(slice: &[T]) -> (&[T], &[T]) {
        let len = slice.len() / N;
        slice.split_at(len * N)
    }

the method call slice.split_at will check that len * N is within
the bounds of slice, this bounds check is after some transformations
turned into the urem seen above and then LLVM fails to optimize it
any further. Adding this optimization would cause this bounds check
to be fully optimized away.

ref: https://github.com/rust-lang/rust/issues/74938

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




More information about the All-commits mailing list