[all-commits] [llvm/llvm-project] 53b00b: [InstSimplify] Fold X {lshr, udiv} C <u X --> true ...

erikdesjardins via All-commits all-commits at lists.llvm.org
Fri Nov 26 13:49:50 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 53b00b821582a95c5186bd76e7e7d12d2697a630
      https://github.com/llvm/llvm-project/commit/53b00b821582a95c5186bd76e7e7d12d2697a630
  Author: Erik Desjardins <erikdesjardinspublic at gmail.com>
  Date:   2021-11-26 (Fri, 26 Nov 2021)

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

  Log Message:
  -----------
  [InstSimplify] Fold X {lshr,udiv} C <u X --> true for nonzero X, non-identity C

This eliminates the bounds check in Rust code like

pub fn mid(data: &[i32]) -> i32 {
  if data.is_empty() { return 0; }
  return data[data.len()/2];
}

(from https://blog.sigplan.org/2021/11/18/undefined-behavior-deserves-a-better-reputation/)

Alive proofs:
lshr https://alive2.llvm.org/ce/z/nyTu8D
udiv https://alive2.llvm.org/ce/z/CNUZH7

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




More information about the All-commits mailing list