[PATCH] D38514: [InstCombine] improve folds for icmp gt/lt (shr X, C1), C2

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 4 09:09:32 PDT 2017


spatel updated this revision to Diff 117680.
spatel added a comment.

Patch updated:

1. Account for exact shifts in the same way as the existing code. It's not clear to me that using exact universally produces a better result, but I'm not proposing to change that here. In https://reviews.llvm.org/rL314907, I duplicated the entire range of tests with exactness to prove that nothing is changing for any of those tests.

2. Rearrange the code to try to make the relationship between all of these variants clearer. It's only the non-exact + greater-than cases where we have to inc/dec the constant. All other cases are just a plain shl of the compare constant.

Here's Alive code for the exact cases:

  Name: ashr_exact_sgt
  Pre: ((C2 << C1) >> C1) == C2
  %sh = ashr exact i8 %x, C1
  %r = icmp sgt i8 %sh, C2
    =>
  %r = icmp sgt i8 %x, (C2 << C1)
  
  Name: ashr_exact_slt
  Pre: ((C2 << C1) >> C1) == C2
  %sh = ashr exact i8 %x, C1
  %r = icmp slt i8 %sh, C2
    =>
  %r = icmp slt i8 %x, (C2 << C1)
  
  Name: lshr_exact_ugt
  Pre: ((C2 << C1) u>> C1) == C2
  %sh = lshr exact i8 %x, C1
  %r = icmp ugt i8 %sh, C2
    =>
  %r = icmp ugt i8 %x, (C2 << C1)
  
  Name: lshr_exact_ult
  Pre: ((C2 << C1) u>> C1) == C2
  %sh = lshr exact i8 %x, C1
  %r = icmp ult i8 %sh, C2
    =>
  %r = icmp ult i8 %x, (C2 << C1)

https://rise4fun.com/Alive/Erp


https://reviews.llvm.org/D38514

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/icmp-shr-lt-gt.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38514.117680.patch
Type: text/x-patch
Size: 8455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171004/201cd465/attachment.bin>


More information about the llvm-commits mailing list