if (Q.isUndefValue(CondC))
return isa<Constant>(FalseVal) ? FalseVal : TrueVal;
- // TODO: Vector constants with undef elements don't simplify.
-
- // select true, X, Y -> X
- if (CondC->isAllOnesValue())
+ // select true, X, Y --> X
+ // select false, X, Y --> Y
+ // For vectors, allow undef/poison elements in the condition to match the
+ // defined elements, so we can eliminate the select.
+ if (match(CondC, m_One()))
return TrueVal;
- // select false, X, Y -> Y
- if (CondC->isNullValue())
+ if (match(CondC, m_Zero()))
return FalseVal;
}
define <2 x i1> @partial_false_undef_condval(<2 x i1> %x) {
; CHECK-LABEL: @partial_false_undef_condval(
-; CHECK-NEXT: [[R:%.*]] = select <2 x i1> <i1 false, i1 poison>, <2 x i1> [[X:%.*]], <2 x i1> <i1 false, i1 poison>
-; CHECK-NEXT: ret <2 x i1> [[R]]
+; CHECK-NEXT: ret <2 x i1> <i1 false, i1 poison>
;
%r = select <2 x i1> <i1 false, i1 poison>, <2 x i1> %x, <2 x i1> <i1 false, i1 poison>
ret <2 x i1> %r
ret <2 x i8> %s
}
-; FIXME: Allow for undef elements in a constant vector condition.
-
define <3 x i8> @vsel_undef_true_op(<3 x i8> %x, <3 x i8> %y) {
; CHECK-LABEL: @vsel_undef_true_op(
-; CHECK-NEXT: [[S:%.*]] = select <3 x i1> <i1 true, i1 undef, i1 true>, <3 x i8> [[X:%.*]], <3 x i8> [[Y:%.*]]
-; CHECK-NEXT: ret <3 x i8> [[S]]
+; CHECK-NEXT: ret <3 x i8> [[X:%.*]]
;
%s = select <3 x i1><i1 1, i1 undef, i1 1>, <3 x i8> %x, <3 x i8> %y
ret <3 x i8> %s
define <3 x i4> @vsel_undef_false_op(<3 x i4> %x, <3 x i4> %y) {
; CHECK-LABEL: @vsel_undef_false_op(
-; CHECK-NEXT: [[S:%.*]] = select <3 x i1> <i1 false, i1 undef, i1 undef>, <3 x i4> [[X:%.*]], <3 x i4> [[Y:%.*]]
-; CHECK-NEXT: ret <3 x i4> [[S]]
+; CHECK-NEXT: ret <3 x i4> [[Y:%.*]]
;
%s = select <3 x i1><i1 0, i1 undef, i1 undef>, <3 x i4> %x, <3 x i4> %y
ret <3 x i4> %s
ret <2 x i8> %s
}
-; FIXME: Allow for undef elements in a constant vector condition.
-
define <3 x i8> @vsel_undef_true_op(<3 x i8> %x, <3 x i8> %y) {
; CHECK-LABEL: @vsel_undef_true_op(
-; CHECK-NEXT: [[S:%.*]] = select <3 x i1> <i1 true, i1 undef, i1 true>, <3 x i8> [[X:%.*]], <3 x i8> [[Y:%.*]]
-; CHECK-NEXT: ret <3 x i8> [[S]]
+; CHECK-NEXT: ret <3 x i8> [[X:%.*]]
;
%s = select <3 x i1><i1 1, i1 undef, i1 1>, <3 x i8> %x, <3 x i8> %y
ret <3 x i8> %s
define <3 x i4> @vsel_undef_false_op(<3 x i4> %x, <3 x i4> %y) {
; CHECK-LABEL: @vsel_undef_false_op(
-; CHECK-NEXT: [[S:%.*]] = select <3 x i1> <i1 false, i1 undef, i1 undef>, <3 x i4> [[X:%.*]], <3 x i4> [[Y:%.*]]
-; CHECK-NEXT: ret <3 x i4> [[S]]
+; CHECK-NEXT: ret <3 x i4> [[Y:%.*]]
;
%s = select <3 x i1><i1 0, i1 undef, i1 undef>, <3 x i4> %x, <3 x i4> %y
ret <3 x i4> %s