[PATCH] D24480: [InstCombine] remove fold: zext(bool) + C -> bool ? C + 1 : C

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 08:36:33 PDT 2016


spatel added a comment.

In https://reviews.llvm.org/D24480#540557, @majnemer wrote:

> I think IR should be canonicalized with ValueTracking in mind (ComputeKnownBits, etc.)


That sounds good, but this raises questions for me:

1. Why is `select i8 %bool, i8 2, i8 1` better for ValueTracking than `zext i1 %bool to i8; add nuw nsw i8 %z, 1`? Is there a fundamental or practical difference in what computeKnownBits can extract from either of those?

2. If select has an advantage and is the canonical form for the case of choosing between constants, then should we remove these existing transforms?
  1. select b, 1, 0 -> zext b to int
  2. select b, -1, 0 -> sext b to int
  3. select b, 0, 1 -> zext !b to int
  4. select b, 0, -1 -> sext !b to int

3. Is the IR for `@selects_are_hard` in my earlier comment canonical? Ie, is a select with variable operands also preferred over an add: `%ret.1 = select i1 %b, i32 %inc5, i32 %.` ?

4. Should I send a note to llvm-dev for a wider audience?


https://reviews.llvm.org/D24480





More information about the llvm-commits mailing list