[all-commits] [llvm/llvm-project] 1711be: [NFC][DAGCombine] Clarify comment for 'A - (A & (B...

Roman Lebedev via All-commits all-commits at lists.llvm.org
Fri Jan 3 07:06:17 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 1711be78f74064d563b165f20debd769929eca06
      https://github.com/llvm/llvm-project/commit/1711be78f74064d563b165f20debd769929eca06
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-01-03 (Fri, 03 Jan 2020)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

  Log Message:
  -----------
  [NFC][DAGCombine] Clarify comment for 'A - (A & (B - 1))' fold


  Commit: e4de8db67eb7a2d64cba078c38f0fd25499013c1
      https://github.com/llvm/llvm-project/commit/e4de8db67eb7a2d64cba078c38f0fd25499013c1
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-01-03 (Fri, 03 Jan 2020)

  Changed paths:
    A llvm/test/CodeGen/X86/align-down-const.ll

  Log Message:
  -----------
  [NFC][DAGCombine][X86] Tests for 'A - (A & C)' pattern (PR44448)

Name: PR44448  ptr - (ptr & C) -> ptr & (~C)
%bias = and i32 %ptr, C
%r = sub i32 %ptr, %bias
  =>
%r = and i32 %ptr, ~C

The main motivational pattern involes pointer-typed values,
so this transform can't really be done in middle-end.

See
  https://bugs.llvm.org/show_bug.cgi?id=44448
  https://reviews.llvm.org/D71499


  Commit: 3d492d7503d197246115eb38e7b1b61143d0c99f
      https://github.com/llvm/llvm-project/commit/3d492d7503d197246115eb38e7b1b61143d0c99f
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-01-03 (Fri, 03 Jan 2020)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    M llvm/test/CodeGen/Thumb2/LowOverheadLoops/fast-fp-loops.ll
    M llvm/test/CodeGen/Thumb2/LowOverheadLoops/mve-float-loops.ll
    M llvm/test/CodeGen/Thumb2/LowOverheadLoops/mve-tail-data-types.ll
    M llvm/test/CodeGen/X86/align-down-const.ll

  Log Message:
  -----------
  [DAGCombine][X86][Thumb2/LowOverheadLoops] `A - (A & C)` -> `A & (~C)` fold (PR44448)

While we do manage to fold integer-typed IR in middle-end,
we can't do that for the main motivational case of pointers.

There is @llvm.ptrmask() intrinsic which may or may not be helpful,
but i'm not sure it is fully considered canonical yet,
not everything is fully aware of it likely.

Name: PR44448  ptr - (ptr & C) -> ptr & (~C)
%bias = and i32 %ptr, C
%r = sub i32 %ptr, %bias
  =>
%r = and i32 %ptr, ~C

See
  https://bugs.llvm.org/show_bug.cgi?id=44448
  https://reviews.llvm.org/D71499


  Commit: d09ac032ee0012d11ae9f9d717eaa6a10cc22a75
      https://github.com/llvm/llvm-project/commit/d09ac032ee0012d11ae9f9d717eaa6a10cc22a75
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-01-03 (Fri, 03 Jan 2020)

  Changed paths:
    A llvm/test/CodeGen/X86/not-of-dec.ll

  Log Message:
  -----------
  [NFC][DAGCombine][X86] '~(X - 1)' pattern tests

The fold 'A - (A & (B - 1))' -> 'A & (0 - B)'
added in 8dab0a4a7d691f2704f1079538e0ef29548db159
is too specific. It should just be 'A - (A & B)' -> 'A & (~B)',
but we currently fail to sink that '~' into `(B - 1)`.

Name: ~(X - 1)  ->  (0 - X)
%o = add i32 %X, -1
%r = xor i32 %o, -1
  =>
%r = sub i32 0, %X

https://rise4fun.com/Alive/rjU


  Commit: 86403c0ff8930e6d4d21d94baa7384e54620f4cf
      https://github.com/llvm/llvm-project/commit/86403c0ff8930e6d4d21d94baa7384e54620f4cf
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-01-03 (Fri, 03 Jan 2020)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    M llvm/test/CodeGen/X86/not-of-dec.ll

  Log Message:
  -----------
  [DAGCombiner] `~(add X, -1)` -> `neg X` fold

The fold 'A - (A & (B - 1))' -> 'A & (0 - B)'
added in 8dab0a4a7d691f2704f1079538e0ef29548db159
is too specific. It should just be 'A - (A & B)' -> 'A & (~B)',
but we currently fail to sink that '~' into `(B - 1)`.

Name: ~(X - 1)  ->  (0 - X)
%o = add i32 %X, -1
%r = xor i32 %o, -1
  =>
%r = sub i32 0, %X

https://rise4fun.com/Alive/rjU


  Commit: df4119c1146997e9a9dcc7129658f561c7eeadb4
      https://github.com/llvm/llvm-project/commit/df4119c1146997e9a9dcc7129658f561c7eeadb4
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-01-03 (Fri, 03 Jan 2020)

  Changed paths:
    M llvm/test/CodeGen/X86/align-down.ll

  Log Message:
  -----------
  [NFC][X86] Add BMI runlines to align-down.ll test


  Commit: 473deaf34bc942f4ff50d4363e47ddcb510b56e0
      https://github.com/llvm/llvm-project/commit/473deaf34bc942f4ff50d4363e47ddcb510b56e0
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-01-03 (Fri, 03 Jan 2020)

  Changed paths:
    A llvm/test/CodeGen/AArch64/sub-of-bias.ll
    A llvm/test/CodeGen/X86/sub-of-bias.ll

  Log Message:
  -----------
  [NFC][X86][AArch64] Add 'A - (A & B)' pattern tests (PR44448)

The fold 'A - (A & (B - 1))' -> 'A & (0 - B)'
added in 8dab0a4a7d691f2704f1079538e0ef29548db159
is too specific. It should just be 'A - (A & B)' -> 'A & (~B)'

Name: X - (X & Y)  ->  X & (~Y)
%o = and i32 %X, %Y
%r = sub i32 %X, %o
  =>
%n = xor i32 %Y, -1
%r = and i32 %X, %n

https://rise4fun.com/Alive/kOUl

See
  https://bugs.llvm.org/show_bug.cgi?id=44448
  https://reviews.llvm.org/D71499


  Commit: 0727e2b90c7b11d5c6be55919c443628d8e2bc6e
      https://github.com/llvm/llvm-project/commit/0727e2b90c7b11d5c6be55919c443628d8e2bc6e
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-01-03 (Fri, 03 Jan 2020)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    M llvm/test/CodeGen/AArch64/align-down.ll
    M llvm/test/CodeGen/AArch64/sub-of-bias.ll
    M llvm/test/CodeGen/X86/align-down.ll
    M llvm/test/CodeGen/X86/sub-of-bias.ll

  Log Message:
  -----------
  [DAGCombiner][X86][AArch64] Generalize `A-(A&B)`->`A&(~B)` fold (PR44448)

The fold 'A - (A & (B - 1))' -> 'A & (0 - B)'
added in 8dab0a4a7d691f2704f1079538e0ef29548db159
is too specific. It should/can just be 'A - (A & B)' -> 'A & (~B)'

Even if we don't manage to fold `~` into B,
we have likely formed `ANDN` node.
Also, this way there's less similar-but-duplicate folds.

Name: X - (X & Y)  ->  X & (~Y)
%o = and i32 %X, %Y
%r = sub i32 %X, %o
  =>
%n = xor i32 %Y, -1
%r = and i32 %X, %n

https://rise4fun.com/Alive/kOUl

See
  https://bugs.llvm.org/show_bug.cgi?id=44448
  https://reviews.llvm.org/D71499


Compare: https://github.com/llvm/llvm-project/compare/69cfbb460e86...0727e2b90c7b


More information about the All-commits mailing list