Try harder to fold icmp with shl nsw as discussed here:
http://lists.llvm.org/pipermail/llvm-dev/2017-January/108749.html
This may eventually help solve:
https://llvm.org/bugs/show_bug.cgi?id=30773
Differential D28406
[InstCombine] icmp sgt (shl nsw X, C1), C0 --> icmp sgt X, C0 >> C1 spatel on Jan 6 2017, 11:41 AM. Authored by
Details Try harder to fold icmp with shl nsw as discussed here: This may eventually help solve:
Diff Detail Event TimelineComment Actions This looks like the signed analogue of the unsigned case on line 1965. Since the unsigned case handles both ugt and ule (but makes the substitutions for ult), perhaps you could handle sle as well: Name: sle %c = shl nsw i8 %x, C1 %d = icmp sle %c, C0 => %d = icmp sle %x, (C0 >> C1) ---------------------------------------- Optimization: sle Done: 1 Optimization is correct! Comment Actions Sure - I was planning to expand this for sle (slt) and the missed eq/ne folds. It will make the code patch slightly bigger to handle sgt/sle in one step, but if that's preferred to match the existing code, I think it's ok. To match LLVM's canonicalization to slt, I think the Alive code becomes: => %b = icmp slt %x, ((C0 - 1) >> C1) + 1
Comment Actions Patch updated: Comment Actions I'm not seeing any test cases for nsw/nuw eq/ne. Should/Can they be added?
Comment Actions This is why I started with a minimal patch. :) Tests that change with this patch and are commented with "Known bits analysis turns this into an equality predicate" are effectively tests of nsw+eq/ne, but I can add explicit checks.
Comment Actions LGTM with just one nit.
|
shl nsw is also shifting out zeroes, no? It's ashr that shifts in sign bits.