[PATCH] D154565: [InstCombine] Fold icmps comparing uadd_sat with a constant

Dhruv Chawla via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 5 22:43:34 PDT 2023


0xdc03 created this revision.
0xdc03 added a reviewer: nikic.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
0xdc03 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch is a continuation of D154206 <https://reviews.llvm.org/D154206>. It introduces a fold for the
operation "uadd_sat(X, C) pred C2" where "C" and "C2" are constants. The
fold is:

uadd_sat(X, C) pred C2

> (X >= ~C) || ((X + C) pred C2) -> when (UINT_MAX pred C2) is true
===================================================================

> (X < ~C)  && ((X + C) pred C2) -> when (UINT_MAX pred C2) is false
====================================================================

These expressions can generally be folded into a simpler expression. As
they can sometimes emit more than one instruction, they are limited to
cases where the "uadd_sat" has only one user.

Proofs: https://alive2.llvm.org/ce/z/wWeirP


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154565

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/test/Transforms/InstCombine/icmp-uadd-sat.ll
  llvm/test/Transforms/InstCombine/icmp-usub-sat.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154565.537587.patch
Type: text/x-patch
Size: 14917 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230706/10a503ff/attachment.bin>


More information about the llvm-commits mailing list