[PATCH] D67725: [InstCombine] dropRedundantMaskingOfLeftShiftInput(): pat. c/d/e with mask (PR42563)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 11:40:30 PDT 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: spatel, nikic, xbolva00.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.

If we have a pattern `(x & (-1 >> maskNbits)) << shiftNbits`,
we already know (have a fold) that will drop the `& (-1 >> maskNbits)`
mask iff `(shiftNbits-maskNbits) s>= 0` (i.e. `shiftNbits u>= maskNbits`).

So even if `(shiftNbits-maskNbits) s< 0`, we can still
fold, we will just need to apply a **constant** mask afterwards:

  Name: c, normal+mask
    %t0 = lshr i32 -1, C1
    %t1 = and i32 %t0, %x
    %r = shl i32 %t1, C2
  =>
    %n0 = shl i32 %x, C2
    %n1 = i32 ((-(C2-C1))+32)
    %n2 = zext i32 %n1 to i64 
    %n3 = lshr i64 -1, %n2
    %n4 = trunc i64 %n3 to i32
    %r = and i32 %n0, %n4

https://rise4fun.com/Alive/gslRa

Naturally, old `%masked` will have to be one-use.
This is not valid for pattern f - where "masking" is done via `ashr`.

https://bugs.llvm.org/show_bug.cgi?id=42563


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67725

Files:
  llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
  llvm/test/Transforms/InstCombine/partally-redundant-left-shift-input-masking-variant-c.ll
  llvm/test/Transforms/InstCombine/partally-redundant-left-shift-input-masking-variant-d.ll
  llvm/test/Transforms/InstCombine/partally-redundant-left-shift-input-masking-variant-e.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67725.220713.patch
Type: text/x-patch
Size: 10734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190918/be13a990/attachment.bin>


More information about the llvm-commits mailing list