[all-commits] [llvm/llvm-project] c4d8d9: [InstCombine] Add tests for folding `(X + Y) - (W ...

goldsteinn via All-commits all-commits at lists.llvm.org
Mon Nov 20 15:59:55 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c4d8d9167938aa09fd7b1492a4abcfcf5bc1a9ca
      https://github.com/llvm/llvm-project/commit/c4d8d9167938aa09fd7b1492a4abcfcf5bc1a9ca
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-11-20 (Mon, 20 Nov 2023)

  Changed paths:
    M llvm/test/Transforms/InstCombine/sub.ll

  Log Message:
  -----------
  [InstCombine] Add tests for folding `(X + Y) - (W + Z)`; NFC


  Commit: dbf6f30926891dfab4d59d0ff0e960c2a31ab472
      https://github.com/llvm/llvm-project/commit/dbf6f30926891dfab4d59d0ff0e960c2a31ab472
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-11-20 (Mon, 20 Nov 2023)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
    M llvm/test/Transforms/InstCombine/sub.ll

  Log Message:
  -----------
  [InstCombine] Add folds for `(X + Y) - (W + Z)`

If `Y` and `Z` are constant then we can simplify to `(X - W) + (Y -
Z)`. If `Y == Z` we can fold to `X - W`.

Note these transform exist outside of InstCombine. The purpose of this
commit is primarily to make it so that folds can generate these
simplifiable patterns without having to worry about creating an inf
loop.


  Commit: d01857803f3593c26118b7f9fe59db71234a3359
      https://github.com/llvm/llvm-project/commit/d01857803f3593c26118b7f9fe59db71234a3359
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-11-20 (Mon, 20 Nov 2023)

  Changed paths:
    M llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
    M llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
    M llvm/test/Transforms/InstCombine/minmax-intrinsics.ll

  Log Message:
  -----------
  [InstCombine] Make `isFreeToInvert` check recursively.

Some Instructions (select/min/max) are inverted by just inverting the
operands. So the answer of whether they are free to invert is really
just whether the operands are free to invert.

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


  Commit: 742c15adcb28701709de7a01f2dc5374e63b9908
      https://github.com/llvm/llvm-project/commit/742c15adcb28701709de7a01f2dc5374e63b9908
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-11-20 (Mon, 20 Nov 2023)

  Changed paths:
    A llvm/test/Transforms/InstCombine/free-inversion.ll

  Log Message:
  -----------
  [InstCombine] Add additional tests for free inversion; NFC


  Commit: 3039691f53487289bab40a4f889810ffd91980c2
      https://github.com/llvm/llvm-project/commit/3039691f53487289bab40a4f889810ffd91980c2
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-11-20 (Mon, 20 Nov 2023)

  Changed paths:
    M llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
    M llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    M llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
    M llvm/test/Transforms/InstCombine/free-inversion.ll
    M llvm/test/Transforms/InstCombine/icmp-of-or-x.ll

  Log Message:
  -----------
  [InstCombine] add `getFreeInverted` to perform folds for free inversion of op

With the current logic of `if(isFreeToInvert(Op)) return Not(Op)` its
fairly easy to either 1) cause regressions or 2) infinite loops
if the folds we have for `Not(Op)` ever de-sync with the cases we
know are freely invertible.

This patch adds `getFreeInverted` which is able to build the free
inverted op along with check for free inversion to alleviate this
problem.


  Commit: b7c0f79926ad0e4f4abe193c82dad8468855eb81
      https://github.com/llvm/llvm-project/commit/b7c0f79926ad0e4f4abe193c82dad8468855eb81
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-11-20 (Mon, 20 Nov 2023)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
    M llvm/test/Transforms/InstCombine/demorgan-sink-not-into-xor.ll
    M llvm/test/Transforms/InstCombine/free-inversion.ll
    M llvm/test/Transforms/InstCombine/icmp-mul-zext.ll
    M llvm/test/Transforms/InstCombine/minmax-intrinsics.ll

  Log Message:
  -----------
  [InstCombine] Replace `isFreeToInvert` + `CreateNot` with `getFreelyInverted`

This is nearly an NFC, the only change is potentially to order that
values are created/names.

Otherwise it is a slight speed boost/simplification to avoid having to
go through the `getFreelyInverted` recursive logic twice to simplify
the extra `not` op.


  Commit: 5271d330770573d2df772aa0fa50d958f44400aa
      https://github.com/llvm/llvm-project/commit/5271d330770573d2df772aa0fa50d958f44400aa
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-11-20 (Mon, 20 Nov 2023)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
    M llvm/test/Transforms/InstCombine/free-inversion.ll

  Log Message:
  -----------
  [InstCombine] Add transform for `~X + ~Y)` -> `-2 - Y - X`

Proof: https://alive2.llvm.org/ce/z/36FySK

Closes #66787.


Compare: https://github.com/llvm/llvm-project/compare/85ee3fc7ec15...5271d3307705


More information about the All-commits mailing list