[InstCombine] add tests for reassociative fsub/fadd expressions; NFC

This commit is contained in:
Sanjay Patel 2020-05-20 12:44:35 -04:00
parent f9a6163f64
commit ad953a1ae1
1 changed files with 89 additions and 3 deletions

View File

@ -30,8 +30,8 @@ define float @test1_unary(float %x, float %y) {
define float @neg_sub_nsz(float %x, float %y) {
; CHECK-LABEL: @neg_sub_nsz(
; CHECK-NEXT: [[TMP1:%.*]] = fsub nsz float [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret float [[TMP1]]
; CHECK-NEXT: [[T2:%.*]] = fsub nsz float [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret float [[T2]]
;
%t1 = fsub float %x, %y
%t2 = fsub nsz float -0.0, %t1
@ -755,7 +755,7 @@ define float @fake_fneg_fsub_fast_extra_use(float %x, float %y) {
; CHECK-LABEL: @fake_fneg_fsub_fast_extra_use(
; CHECK-NEXT: [[NEGX:%.*]] = fneg float [[X:%.*]]
; CHECK-NEXT: call void @use(float [[NEGX]])
; CHECK-NEXT: [[SUB:%.*]] = fsub fast float [[NEGX:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[SUB:%.*]] = fsub fast float [[NEGX]], [[Y:%.*]]
; CHECK-NEXT: ret float [[SUB]]
;
%negx = fsub float -0.0, %x
@ -784,3 +784,89 @@ define float @fneg_fsub_constant(float %x) {
%sub = fsub nsz float %negx, 42.0
ret float %sub
}
define float @fsub_fadd_fsub_reassoc(float %w, float %x, float %y, float %z) {
; CHECK-LABEL: @fsub_fadd_fsub_reassoc(
; CHECK-NEXT: [[S1:%.*]] = fsub reassoc nsz float [[W:%.*]], [[X:%.*]]
; CHECK-NEXT: [[A:%.*]] = fadd reassoc nsz float [[S1]], [[Y:%.*]]
; CHECK-NEXT: [[S2:%.*]] = fsub reassoc nsz float [[A]], [[Z:%.*]]
; CHECK-NEXT: ret float [[S2]]
;
%s1 = fsub reassoc nsz float %w, %x
%a = fadd reassoc nsz float %s1, %y
%s2 = fsub reassoc nsz float %a, %z
ret float %s2
}
define <2 x float> @fsub_fadd_fsub_reassoc_commute(<2 x float> %w, <2 x float> %x, <2 x float> %y, <2 x float> %z) {
; CHECK-LABEL: @fsub_fadd_fsub_reassoc_commute(
; CHECK-NEXT: [[D:%.*]] = fdiv <2 x float> [[Y:%.*]], <float 4.200000e+01, float -4.200000e+01>
; CHECK-NEXT: [[S1:%.*]] = fsub <2 x float> [[W:%.*]], [[X:%.*]]
; CHECK-NEXT: [[A:%.*]] = fadd <2 x float> [[D]], [[S1]]
; CHECK-NEXT: [[S2:%.*]] = fsub fast <2 x float> [[A]], [[Z:%.*]]
; CHECK-NEXT: ret <2 x float> [[S2]]
;
%d = fdiv <2 x float> %y, <float 42.0, float -42.0> ; thwart complexity-based canonicalization
%s1 = fsub <2 x float> %w, %x
%a = fadd <2 x float> %d, %s1
%s2 = fsub fast <2 x float> %a, %z
ret <2 x float> %s2
}
define float @fsub_fadd_fsub_reassoc_twice(float %v, float %w, float %x, float %y, float %z) {
; CHECK-LABEL: @fsub_fadd_fsub_reassoc_twice(
; CHECK-NEXT: [[S1:%.*]] = fsub reassoc nsz float [[V:%.*]], [[W:%.*]]
; CHECK-NEXT: [[S2:%.*]] = fsub reassoc nsz float [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[A:%.*]] = fadd reassoc nsz float [[S1]], [[S2]]
; CHECK-NEXT: [[S3:%.*]] = fsub reassoc nsz float [[A]], [[Z:%.*]]
; CHECK-NEXT: ret float [[S3]]
;
%s1 = fsub reassoc nsz float %v, %w
%s2 = fsub reassoc nsz float %x, %y
%a = fadd reassoc nsz float %s1, %s2
%s3 = fsub reassoc nsz float %a, %z
ret float %s3
}
define float @fsub_fadd_fsub_not_reassoc(float %w, float %x, float %y, float %z) {
; CHECK-LABEL: @fsub_fadd_fsub_not_reassoc(
; CHECK-NEXT: [[S1:%.*]] = fsub fast float [[W:%.*]], [[X:%.*]]
; CHECK-NEXT: [[A:%.*]] = fadd fast float [[S1]], [[Y:%.*]]
; CHECK-NEXT: [[S2:%.*]] = fsub nsz float [[A]], [[Z:%.*]]
; CHECK-NEXT: ret float [[S2]]
;
%s1 = fsub fast float %w, %x
%a = fadd fast float %s1, %y
%s2 = fsub nsz float %a, %z
ret float %s2
}
define float @fsub_fadd_fsub_reassoc_use1(float %w, float %x, float %y, float %z) {
; CHECK-LABEL: @fsub_fadd_fsub_reassoc_use1(
; CHECK-NEXT: [[S1:%.*]] = fsub fast float [[W:%.*]], [[X:%.*]]
; CHECK-NEXT: call void @use(float [[S1]])
; CHECK-NEXT: [[A:%.*]] = fadd fast float [[S1]], [[Y:%.*]]
; CHECK-NEXT: [[S2:%.*]] = fsub fast float [[A]], [[Z:%.*]]
; CHECK-NEXT: ret float [[S2]]
;
%s1 = fsub fast float %w, %x
call void @use(float %s1)
%a = fadd fast float %s1, %y
%s2 = fsub fast float %a, %z
ret float %s2
}
define float @fsub_fadd_fsub_reassoc_use2(float %w, float %x, float %y, float %z) {
; CHECK-LABEL: @fsub_fadd_fsub_reassoc_use2(
; CHECK-NEXT: [[S1:%.*]] = fsub fast float [[W:%.*]], [[X:%.*]]
; CHECK-NEXT: [[A:%.*]] = fadd fast float [[S1]], [[Y:%.*]]
; CHECK-NEXT: call void @use(float [[A]])
; CHECK-NEXT: [[S2:%.*]] = fsub fast float [[A]], [[Z:%.*]]
; CHECK-NEXT: ret float [[S2]]
;
%s1 = fsub fast float %w, %x
%a = fadd fast float %s1, %y
call void @use(float %a)
%s2 = fsub fast float %a, %z
ret float %s2
}