return Cond;
}
- // For any constants that differ by 1, we can transform the select into an
- // extend and add. Use a target hook because some targets may prefer to
- // transform in the other direction.
+ // Use a target hook because some targets may prefer to transform in the
+ // other direction.
if (TLI.convertSelectOfConstantsToMath(VT)) {
+ // For any constants that differ by 1, we can transform the select into an
+ // extend and add.
const APInt &C1Val = C1->getAPIntValue();
const APInt &C2Val = C2->getAPIntValue();
if (C1Val - 1 == C2Val) {
Cond = DAG.getNode(ISD::SIGN_EXTEND, DL, VT, Cond);
return DAG.getNode(ISD::ADD, DL, VT, Cond, N2);
}
+
+ // select Cond, Pow2, 0 --> (zext Cond) << log2(Pow2)
+ if (C1Val.isPowerOf2() && C2Val.isNullValue()) {
+ if (VT != MVT::i1)
+ Cond = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, Cond);
+ SDValue ShAmtC = DAG.getConstant(C1Val.exactLogBase2(), DL, VT);
+ return DAG.getNode(ISD::SHL, DL, VT, Cond, ShAmtC);
+ }
}
return SDValue();
define i8 @sel_shift_bool_i8(i1 %t) {
; CHECK-NOBMI-LABEL: sel_shift_bool_i8:
; CHECK-NOBMI: # %bb.0:
-; CHECK-NOBMI-NEXT: # kill: def $edi killed $edi def $rdi
-; CHECK-NOBMI-NEXT: notb %dil
-; CHECK-NOBMI-NEXT: shlb $7, %dil
-; CHECK-NOBMI-NEXT: leal -128(%rdi), %eax
+; CHECK-NOBMI-NEXT: movl %edi, %eax
+; CHECK-NOBMI-NEXT: shlb $7, %al
; CHECK-NOBMI-NEXT: # kill: def $al killed $al killed $eax
; CHECK-NOBMI-NEXT: retq
;
; CHECK-BMI-LABEL: sel_shift_bool_i8:
; CHECK-BMI: # %bb.0:
-; CHECK-BMI-NEXT: # kill: def $edi killed $edi def $rdi
-; CHECK-BMI-NEXT: notb %dil
-; CHECK-BMI-NEXT: shlb $7, %dil
-; CHECK-BMI-NEXT: leal -128(%rdi), %eax
+; CHECK-BMI-NEXT: movl %edi, %eax
+; CHECK-BMI-NEXT: shlb $7, %al
; CHECK-BMI-NEXT: # kill: def $al killed $al killed $eax
; CHECK-BMI-NEXT: retq
%shl = select i1 %t, i8 128, i8 0