%r = fmul double %x, fsub (double -0.000000e+00, double bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double))
ret double %r
}
+
+define float @negate_if_true(float %x, i1 %cond) {
+; CHECK-LABEL: @negate_if_true(
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], float -1.000000e+00, float 1.000000e+00
+; CHECK-NEXT: [[R:%.*]] = fmul float [[SEL]], [[X:%.*]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %sel = select i1 %cond, float -1.0, float 1.0
+ %r = fmul float %sel, %x
+ ret float %r
+}
+
+define float @negate_if_false(float %x, i1 %cond) {
+; CHECK-LABEL: @negate_if_false(
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], float 1.000000e+00, float -1.000000e+00
+; CHECK-NEXT: [[R:%.*]] = fmul float [[SEL]], [[X:%.*]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %sel = select i1 %cond, float 1.0, float -1.0
+ %r = fmul float %sel, %x
+ ret float %r
+}
+
+define <2 x double> @negate_if_true_commute(<2 x double> %px, i1 %cond) {
+; CHECK-LABEL: @negate_if_true_commute(
+; CHECK-NEXT: [[X:%.*]] = fdiv <2 x double> <double 4.200000e+01, double 4.200000e+01>, [[PX:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x double> <double -1.000000e+00, double -1.000000e+00>, <2 x double> <double 1.000000e+00, double 1.000000e+00>
+; CHECK-NEXT: [[R:%.*]] = fmul <2 x double> [[X]], [[SEL]]
+; CHECK-NEXT: ret <2 x double> [[R]]
+;
+ %x = fdiv <2 x double> <double 42.0, double 42.0>, %px ; thwart complexity-based canonicalization
+ %sel = select i1 %cond, <2 x double> <double -1.0, double -1.0>, <2 x double> <double 1.0, double 1.0>
+ %r = fmul <2 x double> %x, %sel
+ ret <2 x double> %r
+}
+
+define <2 x double> @negate_if_false_commute(<2 x double> %px, <2 x i1> %cond) {
+; CHECK-LABEL: @negate_if_false_commute(
+; CHECK-NEXT: [[X:%.*]] = fdiv <2 x double> <double 4.200000e+01, double 5.100000e+00>, [[PX:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[COND:%.*]], <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double> <double -1.000000e+00, double -1.000000e+00>
+; CHECK-NEXT: [[R:%.*]] = fmul <2 x double> [[X]], [[SEL]]
+; CHECK-NEXT: ret <2 x double> [[R]]
+;
+ %x = fdiv <2 x double> <double 42.0, double 5.1>, %px ; thwart complexity-based canonicalization
+ %sel = select <2 x i1> %cond, <2 x double> <double 1.0, double 1.0>, <2 x double> <double -1.0, double -1.0>
+ %r = fmul <2 x double> %x, %sel
+ ret <2 x double> %r
+}
+
+define float @negate_if_true_extra_use(float %x, i1 %cond) {
+; CHECK-LABEL: @negate_if_true_extra_use(
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], float -1.000000e+00, float 1.000000e+00
+; CHECK-NEXT: call void @use_f32(float [[SEL]])
+; CHECK-NEXT: [[R:%.*]] = fmul float [[SEL]], [[X:%.*]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %sel = select i1 %cond, float -1.0, float 1.0
+ call void @use_f32(float %sel)
+ %r = fmul float %sel, %x
+ ret float %r
+}
+
+define <2 x double> @negate_if_true_wrong_constant(<2 x double> %px, i1 %cond) {
+; CHECK-LABEL: @negate_if_true_wrong_constant(
+; CHECK-NEXT: [[X:%.*]] = fdiv <2 x double> <double 4.200000e+01, double 4.200000e+01>, [[PX:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x double> <double -1.000000e+00, double 0.000000e+00>, <2 x double> <double 1.000000e+00, double 1.000000e+00>
+; CHECK-NEXT: [[R:%.*]] = fmul <2 x double> [[X]], [[SEL]]
+; CHECK-NEXT: ret <2 x double> [[R]]
+;
+ %x = fdiv <2 x double> <double 42.0, double 42.0>, %px ; thwart complexity-based canonicalization
+ %sel = select i1 %cond, <2 x double> <double -1.0, double 0.0>, <2 x double> <double 1.0, double 1.0>
+ %r = fmul <2 x double> %x, %sel
+ ret <2 x double> %r
+}