Fold
%A = icmp eq i8 %x, 0 %B = xor i8 %x, %z %C = select i1 %A, i8 %B, i8 %y
To
%C = select i1 %A, i8 %z, i8 %y
Fixes https://bugs.llvm.org/show_bug.cgi?id=38345
Proof: https://rise4fun.com/Alive/43J
Differential D49954
[InstCombine] Fold Select with binary op xbolva00 on Jul 28 2018, 1:09 AM. Authored by
Details Fold %A = icmp eq i8 %x, 0 %B = xor i8 %x, %z %C = select i1 %A, i8 %B, i8 %y To %C = select i1 %A, i8 %z, i8 %y Fixes https://bugs.llvm.org/show_bug.cgi?id=38345
Diff Detail Event Timeline
Comment Actions This was noted as an inline comment on the test file: this transform is not xor-specific. Example: I think it works for any binop with an "identity constant", so I'd prefer to see this patch generalized to use ConstantExpr::getBinOpIdentity(). Comment Actions I picked it from the list of missed optimizations from here: https://blog.regehr.org/archives/1192 Comment Actions Ok, that's probably still a good-enough motivation. But let's generalize it, so we won't have to deal with every binop and cmp variation individually.
Comment Actions Yes, but please make sure we have at least 1 positive test for each potential opcode that is folded. If you want to leave the non-commutative and FP opcodes out of the initial patch, that's fine, but it should be marked with a TODO comment (and we'll eventually need tests for those). We'll also need tests for the 'ne' predicate.
Comment Actions I'd like to have the folds for non-commutative and FP opcodes first. The undef support would be nice, but I think it's much less likely. |
Add another TODO for the 'ne' predicate.