[PATCH] D24480: [InstCombine] remove fold: zext(bool) + C -> bool ? C + 1 : C
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 12 17:03:41 PDT 2016
spatel added a comment.
In https://reviews.llvm.org/D24480#540517, @majnemer wrote:
> I think r159230 was a step in the wrong direction. An add with a zext seems harder to reason about than a select.
This seems similar to the select -> shuffle canonicalization (https://reviews.llvm.org/D24279) to me. I think it's easier to *read* a select in the IR (I was initially in favor of the select in that case), but it's easier to *combine* the alternative (shuffles or adds). Please let me know if you see an example where a select is easier to combine either in IR or the DAG.
Note that I'm starting from the perspective of:
https://llvm.org/bugs/show_bug.cgi?id=30273
Ie, it's going to take more work to untangle these selects to the adds that most (all?) targets would prefer to codegen:
define i32 @selects_are_hard(i1 zeroext %a, i1 zeroext %b, i1 zeroext %c) {
%. = zext i1 %a to i32
%inc5 = select i1 %a, i32 2, i32 1
%ret.1 = select i1 %b, i32 %inc5, i32 %.
%inc9 = zext i1 %c to i32
%inc9.ret.1 = add nuw nsw i32 %inc9, %ret.1
ret i32 %inc9.ret.1
}
define i32 @adds_are_easy(i1 zeroext %a, i1 zeroext %b, i1 zeroext %c) {
%conv = zext i1 %a to i32
%conv4 = zext i1 %b to i32
%add = add nuw nsw i32 %conv4, %conv
%conv6 = zext i1 %c to i32
%add7 = add nuw nsw i32 %add, %conv6
ret i32 %add7
}
https://reviews.llvm.org/D24480
More information about the llvm-commits
mailing list