2018-03-08 23:46:38 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2010-01-17 08:21:21 +08:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
|
|
|
|
|
|
|
; PR4374
|
2018-03-08 23:46:38 +08:00
|
|
|
|
2018-04-06 01:40:51 +08:00
|
|
|
define float @test1(float %x, float %y) {
|
2018-03-08 23:46:38 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
2018-04-06 01:40:51 +08:00
|
|
|
; CHECK-NEXT: [[T1:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
|
2018-03-08 23:46:38 +08:00
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fsub float -0.000000e+00, [[T1]]
|
|
|
|
; CHECK-NEXT: ret float [[T2]]
|
|
|
|
;
|
2018-04-06 01:40:51 +08:00
|
|
|
%t1 = fsub float %x, %y
|
2018-04-06 00:51:09 +08:00
|
|
|
%t2 = fsub float -0.0, %t1
|
2010-01-17 08:21:21 +08:00
|
|
|
ret float %t2
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:56:54 +08:00
|
|
|
; Can't do anything with the test above because -0.0 - 0.0 = -0.0, but if we have nsz:
|
2018-04-06 01:40:51 +08:00
|
|
|
; -(X - Y) --> Y - X
|
|
|
|
|
2018-04-06 06:56:54 +08:00
|
|
|
define float @neg_sub_nsz(float %x, float %y) {
|
|
|
|
; CHECK-LABEL: @neg_sub_nsz(
|
2018-04-06 05:37:17 +08:00
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fsub nsz float [[Y:%.*]], [[X:%.*]]
|
2018-04-06 01:40:51 +08:00
|
|
|
; CHECK-NEXT: ret float [[T2]]
|
|
|
|
;
|
|
|
|
%t1 = fsub float %x, %y
|
|
|
|
%t2 = fsub nsz float -0.0, %t1
|
|
|
|
ret float %t2
|
|
|
|
}
|
|
|
|
|
2018-04-07 00:30:52 +08:00
|
|
|
declare void @use(float)
|
|
|
|
|
|
|
|
define float @neg_sub_nsz_extra_use(float %x, float %y) {
|
|
|
|
; CHECK-LABEL: @neg_sub_nsz_extra_use(
|
|
|
|
; CHECK-NEXT: [[T1:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fsub nsz float [[Y]], [[X]]
|
|
|
|
; CHECK-NEXT: call void @use(float [[T1]])
|
|
|
|
; CHECK-NEXT: ret float [[T2]]
|
|
|
|
;
|
|
|
|
%t1 = fsub float %x, %y
|
|
|
|
%t2 = fsub nsz float -0.0, %t1
|
|
|
|
call void @use(float %t1)
|
|
|
|
ret float %t2
|
|
|
|
}
|
|
|
|
|
2018-04-06 07:21:15 +08:00
|
|
|
; With nsz: Z - (X - Y) --> Z + (Y - X)
|
2018-04-06 06:56:54 +08:00
|
|
|
|
|
|
|
define float @sub_sub_nsz(float %x, float %y, float %z) {
|
|
|
|
; CHECK-LABEL: @sub_sub_nsz(
|
2018-04-06 07:21:15 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fsub nsz float [[Y:%.*]], [[X:%.*]]
|
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fadd nsz float [[TMP1]], [[Z:%.*]]
|
2018-04-06 06:56:54 +08:00
|
|
|
; CHECK-NEXT: ret float [[T2]]
|
|
|
|
;
|
|
|
|
%t1 = fsub float %x, %y
|
|
|
|
%t2 = fsub nsz float %z, %t1
|
|
|
|
ret float %t2
|
|
|
|
}
|
|
|
|
|
2018-04-06 07:21:15 +08:00
|
|
|
; Same as above: if 'Z' is not -0.0, swap fsub operands and convert to fadd.
|
2018-04-06 06:56:54 +08:00
|
|
|
|
|
|
|
define float @sub_sub_known_not_negzero(float %x, float %y) {
|
|
|
|
; CHECK-LABEL: @sub_sub_known_not_negzero(
|
2018-04-06 07:21:15 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fsub float [[Y:%.*]], [[X:%.*]]
|
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fadd float [[TMP1]], 4.200000e+01
|
2018-04-06 06:56:54 +08:00
|
|
|
; CHECK-NEXT: ret float [[T2]]
|
|
|
|
;
|
|
|
|
%t1 = fsub float %x, %y
|
|
|
|
%t2 = fsub float 42.0, %t1
|
|
|
|
ret float %t2
|
|
|
|
}
|
|
|
|
|
2010-01-17 08:21:21 +08:00
|
|
|
; <rdar://problem/7530098>
|
2018-03-08 23:46:38 +08:00
|
|
|
|
2018-04-06 00:51:09 +08:00
|
|
|
define double @test2(double %x, double %y) {
|
2018-03-08 23:46:38 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
|
|
|
; CHECK-NEXT: [[T1:%.*]] = fadd double [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fsub double [[X]], [[T1]]
|
|
|
|
; CHECK-NEXT: ret double [[T2]]
|
|
|
|
;
|
2010-01-17 08:21:21 +08:00
|
|
|
%t1 = fadd double %x, %y
|
|
|
|
%t2 = fsub double %x, %t1
|
|
|
|
ret double %t2
|
|
|
|
}
|
2017-04-25 01:24:37 +08:00
|
|
|
|
2018-04-06 00:51:09 +08:00
|
|
|
; X - C --> X + (-C)
|
|
|
|
|
|
|
|
define float @constant_op1(float %x, float %y) {
|
|
|
|
; CHECK-LABEL: @constant_op1(
|
|
|
|
; CHECK-NEXT: [[R:%.*]] = fadd float [[X:%.*]], -4.200000e+01
|
|
|
|
; CHECK-NEXT: ret float [[R]]
|
|
|
|
;
|
|
|
|
%r = fsub float %x, 42.0
|
|
|
|
ret float %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x float> @constant_op1_vec(<2 x float> %x, <2 x float> %y) {
|
|
|
|
; CHECK-LABEL: @constant_op1_vec(
|
|
|
|
; CHECK-NEXT: [[R:%.*]] = fadd <2 x float> [[X:%.*]], <float -4.200000e+01, float 4.200000e+01>
|
|
|
|
; CHECK-NEXT: ret <2 x float> [[R]]
|
|
|
|
;
|
|
|
|
%r = fsub <2 x float> %x, <float 42.0, float -42.0>
|
|
|
|
ret <2 x float> %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x float> @constant_op1_vec_undef(<2 x float> %x, <2 x float> %y) {
|
|
|
|
; CHECK-LABEL: @constant_op1_vec_undef(
|
2018-04-06 01:06:45 +08:00
|
|
|
; CHECK-NEXT: [[R:%.*]] = fadd <2 x float> [[X:%.*]], <float 0x7FF8000000000000, float 4.200000e+01>
|
2018-04-06 00:51:09 +08:00
|
|
|
; CHECK-NEXT: ret <2 x float> [[R]]
|
|
|
|
;
|
|
|
|
%r = fsub <2 x float> %x, <float undef, float -42.0>
|
|
|
|
ret <2 x float> %r
|
|
|
|
}
|
|
|
|
|
|
|
|
; X - (-Y) --> X + Y
|
|
|
|
|
|
|
|
define float @neg_op1(float %x, float %y) {
|
|
|
|
; CHECK-LABEL: @neg_op1(
|
|
|
|
; CHECK-NEXT: [[R:%.*]] = fadd float [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: ret float [[R]]
|
|
|
|
;
|
|
|
|
%negy = fsub float -0.0, %y
|
|
|
|
%r = fsub float %x, %negy
|
|
|
|
ret float %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x float> @neg_op1_vec(<2 x float> %x, <2 x float> %y) {
|
|
|
|
; CHECK-LABEL: @neg_op1_vec(
|
|
|
|
; CHECK-NEXT: [[R:%.*]] = fadd <2 x float> [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: ret <2 x float> [[R]]
|
|
|
|
;
|
|
|
|
%negy = fsub <2 x float> <float -0.0, float -0.0>, %y
|
|
|
|
%r = fsub <2 x float> %x, %negy
|
|
|
|
ret <2 x float> %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x float> @neg_op1_vec_undef(<2 x float> %x, <2 x float> %y) {
|
|
|
|
; CHECK-LABEL: @neg_op1_vec_undef(
|
2018-04-06 01:06:45 +08:00
|
|
|
; CHECK-NEXT: [[R:%.*]] = fadd <2 x float> [[X:%.*]], [[Y:%.*]]
|
2018-04-06 00:51:09 +08:00
|
|
|
; CHECK-NEXT: ret <2 x float> [[R]]
|
|
|
|
;
|
|
|
|
%negy = fsub <2 x float> <float -0.0, float undef>, %y
|
|
|
|
%r = fsub <2 x float> %x, %negy
|
|
|
|
ret <2 x float> %r
|
|
|
|
}
|
|
|
|
|