[PATCH] D72396: [InstCombine] fold zext of masked bit set/clear

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 06:25:48 PST 2020


spatel created this revision.
spatel added reviewers: lebedev.ri, xbolva00, nikic, kadircet.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: LLVM.
spatel edited the summary of this revision.

This does not solve PR17101, but it is one of the
underlying diffs noted here:
https://bugs.llvm.org/show_bug.cgi?id=17101#c8

We could ease the one-use checks for the 'clear'
(no 'not' op) half of the transform, but I do not
know if that asymmetry would make things better
or worse.

Proofs:
https://rise4fun.com/Alive/uVB

  Name: masked bit set
  %sh1 = shl i32 1, %y
  %and = and i32 %sh1, %x
  %cmp = icmp ne i32 %and, 0
  %r = zext i1 %cmp to i32
  =>
  %s = lshr i32 %x, %y
  %r = and i32 %s, 1
  
  Name: masked bit clear
  %sh1 = shl i32 1, %y
  %and = and i32 %sh1, %x
  %cmp = icmp eq i32 %and, 0
  %r = zext i1 %cmp to i32
  =>
  %xn = xor i32 %x, -1
  %s = lshr i32 %xn, %y
  %r = and i32 %s, 1

Note: this is a re-post of a patch that I committed at:
rGa041c4ec6f7a <https://reviews.llvm.org/rGa041c4ec6f7aa659b235cb67e9231a05e0a33b7d>

I thought the change was small and obviously good, so I did not post it for pre-commit review per policy:
http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

The commit was reverted though:
rGb212eb7159b40c98b3c40619b82b996fb903282b <https://reviews.llvm.org/rGb212eb7159b40c98b3c40619b82b996fb903282b>

So either I am not seeing the problem with this patch, or it is uncovering a problem in another part of LLVM.


https://reviews.llvm.org/D72396

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/zext.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72396.236805.patch
Type: text/x-patch
Size: 7504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200108/f5d3deee/attachment.bin>


More information about the llvm-commits mailing list