[PATCH] D36498: [InstCombine] Teach foldSelectICmpAnd to recognize a (icmp slt trunc X, 0) and (icmp sgt trunc X, -1) as equivalent to an and with the sign bit of the truncated type

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 11:18:54 PDT 2017


craig.topper updated this revision to Diff 111212.
craig.topper added a comment.

Rewritten to use decomposeBitTestICmp.

The use of decomposeBitTestICmp removes the truncate check I had in the old patch. It's not really needed. We just care about the mask. This exposed that I almost broke another transform in here that used ashr to generate constants for selects. Reordered the combines a little and added a TODO to try to merge these combines. We may want to look at turning the lshr, and, or sequence into the ashr pattern independently too.

Looks like this also exposed that canEvaluateZExtd can't handle vector shifts correctly. So that prevented the zext and trunc from being folded in the vector tests. I'll submit a follow up patch for that.


https://reviews.llvm.org/D36498

Files:
  lib/Transforms/InstCombine/InstCombineSelect.cpp
  test/Transforms/InstCombine/select-with-bitwise-ops.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36498.111212.patch
Type: text/x-patch
Size: 9540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170815/6115e779/attachment.bin>


More information about the llvm-commits mailing list