[PATCH] Fix optimisations of SELECT_CC which assumed result is boolean
Tim Northover
t.p.northover at gmail.com
Fri Nov 14 07:23:07 PST 2014
Hi Oliver,
Thanks for updating the patch. Nearly there, I think, but there's one improvement we can make:
================
Comment at: lib/CodeGen/SelectionDAG/DAGCombiner.cpp:3833
@@ -3828,4 +3832,3 @@
// fold !(x cc y) -> (x !cc y)
- if (N1C && N1C->getAPIntValue().isAllOnesValue() &&
- isSetCCEquivalent(N0, LHS, RHS, CC)) {
+ if (N1C && TLI.isConstTrueVal(N1C) && isSetCCEquivalent(N0, LHS, RHS, CC)) {
bool isInt = LHS.getValueType().isInteger();
----------------
isConstTrueVal is actually a bit more general than this (or it would be if it didn't have a bug itself), handling BUILD_VECTOR as well as ConstantSDNode. So you can probably drop the N1C check and use N1 directly.
E.g.
define <2 x i64> @foo(<2 x i64> %lhs, <2 x i64> %rhs) {
%tst = icmp eq <2 x i64> %lhs, %rhs
%ntst = xor <2 x i1> %tst, <i1 1 , i1 undef>
%btst = sext <2 x i1> %ntst to <2 x i64>
ret <2 x i64> %btst
}
(The undef should be a 1, I think, but that bug in isConstTrueVal (& isConstFalseVal) means the optimisation triggers with undef instead).
http://reviews.llvm.org/D6249
More information about the llvm-commits
mailing list