[PATCH] D86243: [InstCombine] canonicalize 'not' ops before logical shifts

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 13:13:34 PDT 2020


spatel created this revision.
spatel added reviewers: bjope, efriedma, lebedev.ri.
Herald added subscribers: javed.absar, hiraditya, mcrosier.
Herald added a project: LLVM.
spatel requested review of this revision.

This reverses the existing transform that would uniformly canonicalize any 'xor' after any shift. In the case of logical shifts, that turns a 'not' into an arbitrary 'xor' with constant, and that's probably not as good for analysis, SCEV, or codegen.

The SCEV motivating case is discussed in:
http://bugs.llvm.org/PR47136

There's an analysis motivating case at:
http://bugs.llvm.org/PR38781

I did draft a patch that would do the same for 'ashr' but that's questionable because it's just swapping the position of a 'not' and uncovers at least 2 missing folds that we would probably need to deal with as preliminary steps.

Alive proofs:
https://rise4fun.com/Alive/BBV

  Name: shift right of 'not'
  Pre: C2 == (-1 u>> C1)
  %a = lshr i8 %x, C1
  %r = xor i8 %a, C2
    =>
  %n = xor i8 %x, -1
  %r = lshr i8 %n, C1
  
  Name: shift left of 'not'
  Pre: C2 == (-1 << C1)
  %a = shl i8 %x, C1
  %r = xor i8 %a, C2
    =>
  %n = xor i8 %x, -1
  %r = shl i8 %n, C1
  
  Name: ashr of 'not'
  %a = ashr i8 %x, 1
  %r = xor i8 %a, -1
    =>
  %n = xor i8 %x, -1
  %r = ashr i8 %n, 1


https://reviews.llvm.org/D86243

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
  llvm/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
  llvm/test/Transforms/InstCombine/and-xor-merge.ll
  llvm/test/Transforms/InstCombine/compare-signs.ll
  llvm/test/Transforms/InstCombine/icmp.ll
  llvm/test/Transforms/InstCombine/xor.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86243.286641.patch
Type: text/x-patch
Size: 9471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200819/b5a871f0/attachment-0001.bin>


More information about the llvm-commits mailing list