ret <2 x float> %r
}
+define <2 x float> @unary_neg_neg(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @unary_neg_neg(
+; CHECK-NEXT: [[TMP1:%.*]] = call <2 x float> @llvm.minimum.v2f32(<2 x float> [[X:%.*]], <2 x float> [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %negx = fneg <2 x float> %x
+ %negy = fneg <2 x float> %y
+ %r = call <2 x float> @llvm.maximum.v2f32(<2 x float> %negx, <2 x float> %negy)
+ ret <2 x float> %r
+}
+
; FMF is not required, but it should be propagated from the intrinsic (not the fnegs).
define float @neg_neg_vec_fmf(float %x, float %y) {
ret float %r
}
+define float @unary_neg_neg_vec_fmf(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_neg_vec_fmf(
+; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.minimum.f32(float [[X:%.*]], float [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fsub fast float -0.000000e+00, [[TMP1]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %negx = fneg arcp float %x
+ %negy = fneg afn float %y
+ %r = call fast float @llvm.maximum.f32(float %negx, float %negy)
+ ret float %r
+}
+
; 1 extra use of an intermediate value should still allow the fold,
; but 2 would require more instructions than we started with.
ret float %r
}
+define float @unary_neg_neg_extra_use_x(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_x(
+; CHECK-NEXT: [[NEGX:%.*]] = fneg float [[X:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.minimum.f32(float [[X]], float [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fsub float -0.000000e+00, [[TMP1]]
+; CHECK-NEXT: call void @use(float [[NEGX]])
+; CHECK-NEXT: ret float [[R]]
+;
+ %negx = fneg float %x
+ %negy = fneg float %y
+ %r = call float @llvm.maximum.f32(float %negx, float %negy)
+ call void @use(float %negx)
+ ret float %r
+}
+
define float @neg_neg_extra_use_y(float %x, float %y) {
; CHECK-LABEL: @neg_neg_extra_use_y(
; CHECK-NEXT: [[NEGY:%.*]] = fsub float -0.000000e+00, [[Y:%.*]]
ret float %r
}
+define float @unary_neg_neg_extra_use_y(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_y(
+; CHECK-NEXT: [[NEGY:%.*]] = fneg float [[Y:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float [[Y]])
+; CHECK-NEXT: [[R:%.*]] = fsub float -0.000000e+00, [[TMP1]]
+; CHECK-NEXT: call void @use(float [[NEGY]])
+; CHECK-NEXT: ret float [[R]]
+;
+ %negx = fneg float %x
+ %negy = fneg float %y
+ %r = call float @llvm.maximum.f32(float %negx, float %negy)
+ call void @use(float %negy)
+ ret float %r
+}
+
define float @neg_neg_extra_use_x_and_y(float %x, float %y) {
; CHECK-LABEL: @neg_neg_extra_use_x_and_y(
; CHECK-NEXT: [[NEGX:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
call void @use(float %negy)
ret float %r
}
+
+define float @unary_neg_neg_extra_use_x_and_y(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_x_and_y(
+; CHECK-NEXT: [[NEGX:%.*]] = fneg float [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fneg float [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.maximum.f32(float [[NEGX]], float [[NEGY]])
+; CHECK-NEXT: call void @use(float [[NEGX]])
+; CHECK-NEXT: call void @use(float [[NEGY]])
+; CHECK-NEXT: ret float [[R]]
+;
+ %negx = fneg float %x
+ %negy = fneg float %y
+ %r = call float @llvm.maximum.f32(float %negx, float %negy)
+ call void @use(float %negx)
+ call void @use(float %negy)
+ ret float %r
+}
ret double %r
}
+define double @unary_neg_neg(double %x, double %y) {
+; CHECK-LABEL: @unary_neg_neg(
+; CHECK-NEXT: [[TMP1:%.*]] = call double @llvm.maximum.f64(double [[X:%.*]], double [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fsub double -0.000000e+00, [[TMP1]]
+; CHECK-NEXT: ret double [[R]]
+;
+ %negx = fneg double %x
+ %negy = fneg double %y
+ %r = call double @llvm.minimum.f64(double %negx, double %negy)
+ ret double %r
+}
+
; FMF is not required, but it should be propagated from the intrinsic (not the fnegs).
; Also, make sure this works with vectors.
ret <2 x double> %r
}
+define <2 x double> @unary_neg_neg_vec_fmf(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: @unary_neg_neg_vec_fmf(
+; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf <2 x double> @llvm.maximum.v2f64(<2 x double> [[X:%.*]], <2 x double> [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fsub nnan ninf <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[TMP1]]
+; CHECK-NEXT: ret <2 x double> [[R]]
+;
+ %negx = fneg reassoc <2 x double> %x
+ %negy = fneg fast <2 x double> %y
+ %r = call nnan ninf <2 x double> @llvm.minimum.v2f64(<2 x double> %negx, <2 x double> %negy)
+ ret <2 x double> %r
+}
+
; 1 extra use of an intermediate value should still allow the fold,
; but 2 would require more instructions than we started with.
ret double %r
}
+define double @unary_neg_neg_extra_use_x(double %x, double %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_x(
+; CHECK-NEXT: [[NEGX:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = call double @llvm.maximum.f64(double [[X]], double [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fsub double -0.000000e+00, [[TMP1]]
+; CHECK-NEXT: call void @use(double [[NEGX]])
+; CHECK-NEXT: ret double [[R]]
+;
+ %negx = fneg double %x
+ %negy = fneg double %y
+ %r = call double @llvm.minimum.f64(double %negx, double %negy)
+ call void @use(double %negx)
+ ret double %r
+}
+
define double @neg_neg_extra_use_y(double %x, double %y) {
; CHECK-LABEL: @neg_neg_extra_use_y(
; CHECK-NEXT: [[NEGY:%.*]] = fsub double -0.000000e+00, [[Y:%.*]]
ret double %r
}
+define double @unary_neg_neg_extra_use_y(double %x, double %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_y(
+; CHECK-NEXT: [[NEGY:%.*]] = fneg double [[Y:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = call double @llvm.maximum.f64(double [[X:%.*]], double [[Y]])
+; CHECK-NEXT: [[R:%.*]] = fsub double -0.000000e+00, [[TMP1]]
+; CHECK-NEXT: call void @use(double [[NEGY]])
+; CHECK-NEXT: ret double [[R]]
+;
+ %negx = fneg double %x
+ %negy = fneg double %y
+ %r = call double @llvm.minimum.f64(double %negx, double %negy)
+ call void @use(double %negy)
+ ret double %r
+}
+
define double @neg_neg_extra_use_x_and_y(double %x, double %y) {
; CHECK-LABEL: @neg_neg_extra_use_x_and_y(
; CHECK-NEXT: [[NEGX:%.*]] = fsub double -0.000000e+00, [[X:%.*]]
call void @use(double %negy)
ret double %r
}
+
+define double @unary_neg_neg_extra_use_x_and_y(double %x, double %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_x_and_y(
+; CHECK-NEXT: [[NEGX:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fneg double [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call double @llvm.minimum.f64(double [[NEGX]], double [[NEGY]])
+; CHECK-NEXT: call void @use(double [[NEGX]])
+; CHECK-NEXT: call void @use(double [[NEGY]])
+; CHECK-NEXT: ret double [[R]]
+;
+ %negx = fneg double %x
+ %negy = fneg double %y
+ %r = call double @llvm.minimum.f64(double %negx, double %negy)
+ call void @use(double %negx)
+ call void @use(double %negy)
+ ret double %r
+}