[all-commits] [llvm/llvm-project] 1c2163: [NFC][InstCombine] Tests for x s/EXACT (-1 << y) ...

Roman Lebedev via All-commits all-commits at lists.llvm.org
Thu Aug 6 13:45:38 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 1c21635c94df0e680cbb0797a64d09a63f619fc0
      https://github.com/llvm/llvm-project/commit/1c21635c94df0e680cbb0797a64d09a63f619fc0
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-08-06 (Thu, 06 Aug 2020)

  Changed paths:
    A llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll

  Log Message:
  -----------
  [NFC][InstCombine] Tests for  x s/EXACT (-1 << y)  pattern


  Commit: 8633a0d985f1abc8f81dba5f699d5df627e6a9f1
      https://github.com/llvm/llvm-project/commit/8633a0d985f1abc8f81dba5f699d5df627e6a9f1
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-08-06 (Thu, 06 Aug 2020)

  Changed paths:
    A llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll

  Log Message:
  -----------
  [NFC][InstCombine] Better tests for  x s/EXACT (1 << y)  pattern


  Commit: 442cb88f5344560e49fab681a9c909654d85fcc7
      https://github.com/llvm/llvm-project/commit/442cb88f5344560e49fab681a9c909654d85fcc7
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-08-06 (Thu, 06 Aug 2020)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    M llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll

  Log Message:
  -----------
  [InstCombine] Generalize  sdiv exact X, 1<<C  -->  ashr exact X, C  fold to handle non-splat vectors


  Commit: 47aec80e4afc8e3746e09f4c9d309cf8941f68cc
      https://github.com/llvm/llvm-project/commit/47aec80e4afc8e3746e09f4c9d309cf8941f68cc
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-08-06 (Thu, 06 Aug 2020)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp

  Log Message:
  -----------
  [NFC][InstCombine] Negator: add a comment about negating exact arithmentic shift


  Commit: 7ce76b06ec908a85205d4dc7af6e73d5ecc26251
      https://github.com/llvm/llvm-project/commit/7ce76b06ec908a85205d4dc7af6e73d5ecc26251
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-08-06 (Thu, 06 Aug 2020)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    M llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll

  Log Message:
  -----------
  [InstCombine] Fold  sdiv exact X, -1<<C  -->  -(ashr exact X, C)

While that does increases instruction count,
shift is obviously better than a division.

Name: base
Pre: (1<<C1) >= 0
%o0 = shl i8 1, C1
%r = sdiv exact i8 C0, %o0
  =>
%r = ashr exact i8 C0, C1

Name: neg
%o0 = shl i8 -1, C1
%r = sdiv exact i8 C0, %o0
  =>
%t0 = ashr exact i8 C0, C1
%r = sub i8 0, %t0

Name: reverse
Pre: C1 != 0 && C1 u< 8
%t0 = ashr exact i8 C0, C1
%r = sub i8 0, %t0
  =>
%o0 = shl i8 -1, C1
%r = sdiv exact i8 C0, %o0

https://rise4fun.com/Alive/MRplf


  Commit: a404acb86af7d62390a2599bb86bba2c5f840f68
      https://github.com/llvm/llvm-project/commit/a404acb86af7d62390a2599bb86bba2c5f840f68
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-08-06 (Thu, 06 Aug 2020)

  Changed paths:
    M llvm/test/Transforms/InstCombine/mul.ll
    M llvm/test/Transforms/InstCombine/sub-of-negatible.ll

  Log Message:
  -----------
  [NFC][InstCombine] Add some more tests for negation sinking into mul


  Commit: 0c1c756a31536666a7b6f5bdb744dbce923a0c9e
      https://github.com/llvm/llvm-project/commit/0c1c756a31536666a7b6f5bdb744dbce923a0c9e
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-08-06 (Thu, 06 Aug 2020)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    M llvm/test/Transforms/InstCombine/mul.ll

  Log Message:
  -----------
  [InstCombine] Generalize  %x * (-1<<C)  -->  (-%x) * (1<<C)  fold

Multiplication is commutative, and either of operands can be negative,
so if the RHS is a negated power-of-two, we should try to make it
true power-of-two (which will allow us to turn it into a left-shift),
by trying to sink the negation down into LHS op.

But, we shouldn't re-invent the logic for sinking negation,
let's just use Negator for that.

Tests and original patch by: Simon Pilgrim @RKSimon!

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


  Commit: be02adfad7acf8040ad025b58052b3838db7e23b
      https://github.com/llvm/llvm-project/commit/be02adfad7acf8040ad025b58052b3838db7e23b
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-08-06 (Thu, 06 Aug 2020)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    M llvm/test/Transforms/InstCombine/mul.ll

  Log Message:
  -----------
  [InstCombine] Fold  (x + C1) * (-1<<C2)  -->  (-C1 - x) * (1<<C2)

Negator knows how to do this, but the one-use reasoning is getting
a bit muddy here, we don't really want to increase instruction count,
so we need to both lie that "IsNegation" and have an one-use check
on the outermost LHS value.


Compare: https://github.com/llvm/llvm-project/compare/0fa520af6734...be02adfad7ac


More information about the All-commits mailing list