[all-commits] [llvm/llvm-project] 66b669: [NFC][InstCombine] Add some tests with sdiv-by-neg...

Roman Lebedev via All-commits all-commits at lists.llvm.org
Fri Jul 17 12:50:36 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 66b66988e613a2349d06600e12601ecbe8032256
      https://github.com/llvm/llvm-project/commit/66b66988e613a2349d06600e12601ecbe8032256
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-07-17 (Fri, 17 Jul 2020)

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

  Log Message:
  -----------
  [NFC][InstCombine] Add some tests with sdiv-by-negative-power-of-two


  Commit: 0fdcca07ad2c0bdc2cdd40ba638109926f4f513b
      https://github.com/llvm/llvm-project/commit/0fdcca07ad2c0bdc2cdd40ba638109926f4f513b
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-07-17 (Fri, 17 Jul 2020)

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

  Log Message:
  -----------
  [InstCombine] Fold  X sdiv (-1 << C) -> -(X u>> Y)  iff X is non-negative

This is the one i'm seeing as missed optimization,
although there are likely other possibilities, as usual.

There are 4 variants of a general sdiv->udiv fold:
https://rise4fun.com/Alive/VS6

Name: v0
Pre: C0 >= 0 && C1 >= 0
%r = sdiv i8 C0, C1
  =>
%r = udiv i8 C0, C1

Name: v1
Pre: C0 <= 0 && C1 >= 0
%r = sdiv i8 C0, C1
  =>
%t0 = udiv i8 -C0, C1
%r = sub i8 0, %t0

Name: v2
Pre: C0 >= 0 && C1 <= 0
%r = sdiv i8 C0, C1
  =>
%t0 = udiv i8 C0, -C1
%r = sub i8 0, %t0

Name: v3
Pre: C0 <= 0 && C1 <= 0
%r = sdiv i8 C0, C1
  =>
%r = udiv i8 -C0, -C1


If we really don't like sdiv (more than udiv that is),
and are okay with increasing instruction count (2 new negations),
and we ensure that we don't undo the fold,
then we could just implement these..


Compare: https://github.com/llvm/llvm-project/compare/b30fa1c3dab7...0fdcca07ad2c


More information about the All-commits mailing list