[PATCH] D84664: [InstCombine] Fold shift-select if all the operands are constant

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 02:10:30 PDT 2020


lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

In D84664#2177964 <https://reviews.llvm.org/D84664#2177964>, @fvrmatteo wrote:

> I reduced the bit-width to i8 and the same issue is happening when I only disable the `if (!I->hasOneUse()) return false;` line from **canEvaluateShifted**. Is there a chance that disabling the check is not sufficient but that would actually require more changes?
>
> Attached you can find the narrowed down test case executed with the disabled line and its debug output.F12425130: instcombine.log <https://reviews.llvm.org/F12425130>
>
> F12425129: lshr-select-const-i8.ll <https://reviews.llvm.org/F12425129>

Please just post IR inline, it's super inconvient to extract it from attachmensts
As i suspected, the alive-tv result is red herring:

  $ /repositories/alive2/build-Clang-release/alive-tv /tmp/test.ll 
  
  ----------------------------------------
  define i8 @src(i1 %arg) {
  %entry:
    %v0 = select i1 %arg, i8 64, i8 0
    %v1 = lshr exact i8 %v0, 6
    %v2 = xor i8 %v1, 1
    %v3 = shl nuw i8 %v0, 57
    %v4 = ashr exact i8 %v3, 63
    %v5 = sub nsw i8 0, %v2
    %v6 = and i8 %v5, 91
    %v7 = and i8 %v4, 61
    %v8 = add nsw nuw i8 %v7, %v6
    ret i8 %v8
  }
  =>
  define i8 @tgt(i1 %arg) {
  %entry:
    %v0 = zext i1 %arg to i8
    %0 = or i8 %v0, 126
    %v2.neg = add nuw i8 %0, 1
    %v6 = and i8 %v2.neg, 91
    ret i8 %v6
  }
  Transformation seems to be correct!

It is generally not correct to specify `--disable-undef-input` / `--disable-poison-input`.
If this optimization can be achieved by relaxing existing optimizations, let's do that first.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84664/new/

https://reviews.llvm.org/D84664



More information about the llvm-commits mailing list