1 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3 ; X * Y (when Y is a boolean) --> Y ? X : 0
5 define float @fmul_bool(float %x, i1 %y) {
6 ; CHECK-LABEL: @fmul_bool(
7 ; CHECK-NEXT: [[M:%.*]] = select nnan nsz i1 [[Y:%.*]], float [[X:%.*]], float 0.000000e+00
8 ; CHECK-NEXT: ret float [[M]]
10 %z = uitofp i1 %y to float
11 %m = fmul nnan nsz float %z, %x
15 define <2 x float> @fmul_bool_vec(<2 x float> %x, <2 x i1> %y) {
16 ; CHECK-LABEL: @fmul_bool_vec(
17 ; CHECK-NEXT: [[M:%.*]] = select nnan nsz <2 x i1> [[Y:%.*]], <2 x float> [[X:%.*]], <2 x float> zeroinitializer
18 ; CHECK-NEXT: ret <2 x float> [[M]]
20 %z = uitofp <2 x i1> %y to <2 x float>
21 %m = fmul nnan nsz <2 x float> %z, %x
25 define <2 x float> @fmul_bool_vec_commute(<2 x float> %px, <2 x i1> %y) {
26 ; CHECK-LABEL: @fmul_bool_vec_commute(
27 ; CHECK-NEXT: [[X:%.*]] = fmul nnan nsz <2 x float> [[PX:%.*]], [[PX]]
28 ; CHECK-NEXT: [[M:%.*]] = select nnan nsz <2 x i1> [[Y:%.*]], <2 x float> [[X]], <2 x float> zeroinitializer
29 ; CHECK-NEXT: ret <2 x float> [[M]]
31 %x = fmul nnan nsz <2 x float> %px, %px ; thwart complexity-based canonicalization
32 %z = uitofp <2 x i1> %y to <2 x float>
33 %m = fmul nnan nsz <2 x float> %x, %z