[all-commits] [llvm/llvm-project] b3fdb7: [InstCombine] Combine lshr of add -> (a + b < a)

Pierre van Houtryve via All-commits all-commits at lists.llvm.org
Tue Jan 10 00:37:37 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b3fdb7b0cba49e7f24fd8207c677b0541045755c
      https://github.com/llvm/llvm-project/commit/b3fdb7b0cba49e7f24fd8207c677b0541045755c
  Author: Pierre van Houtryve <pierre.vanhoutryve at amd.com>
  Date:   2023-01-10 (Tue, 10 Jan 2023)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineInternal.h
    M llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
    M llvm/test/Transforms/InstCombine/lshr.ll
    M llvm/test/Transforms/InstCombine/shift-add.ll

  Log Message:
  -----------
  [InstCombine] Combine lshr of add -> (a + b < a)

Tries to perform
  (lshr (add (zext X), (zext Y)), K)
  ->  (icmp ult (add X, Y), X)
  where
    - The add's operands are zexts from a K-bits integer to a bigger type.
    - The add is only used by the shr, or by iK (or narrower) truncates.
    - The lshr type has more than 2 bits (other types are boolean math).
    - K > 1

This seems to be a pattern that just comes from OpenCL front-ends, so adding DAG/GISel combines doesn't seem to be worth the complexity.

Original patch D107552 by @abinavpp - adapted to use (a + b < a) instead of uaddo following discussion on the review.
See this issue https://github.com/RadeonOpenCompute/ROCm/issues/488

Reviewed By: spatel

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




More information about the All-commits mailing list