2018-03-02 07:41:03 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2014-08-14 23:23:01 +08:00
|
|
|
; RUN: opt < %s -reassociate -gvn -instcombine -S | FileCheck %s
|
|
|
|
|
|
|
|
; With reassociation, constant folding can eliminate the 12 and -12 constants.
|
|
|
|
define float @test1(float %arg) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[ARG_NEG:%.*]] = fsub fast float -0.000000e+00, [[ARG:%.*]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[ARG_NEG]]
|
|
|
|
;
|
|
|
|
%t1 = fsub fast float -1.200000e+01, %arg
|
|
|
|
%t2 = fadd fast float %t1, 1.200000e+01
|
|
|
|
ret float %t2
|
2014-08-14 23:23:01 +08:00
|
|
|
}
|
|
|
|
|
2018-04-15 03:18:28 +08:00
|
|
|
; Check again using the minimal subset of FMF.
|
|
|
|
; Both 'reassoc' and 'nsz' are required.
|
|
|
|
define float @test1_minimal(float %arg) {
|
|
|
|
; CHECK-LABEL: @test1_minimal(
|
|
|
|
; CHECK-NEXT: [[ARG_NEG:%.*]] = fsub reassoc nsz float -0.000000e+00, [[ARG:%.*]]
|
|
|
|
; CHECK-NEXT: ret float [[ARG_NEG]]
|
|
|
|
;
|
|
|
|
%t1 = fsub reassoc nsz float -1.200000e+01, %arg
|
|
|
|
%t2 = fadd reassoc nsz float %t1, 1.200000e+01
|
|
|
|
ret float %t2
|
|
|
|
}
|
|
|
|
|
|
|
|
; Verify the fold is not done with only 'reassoc' ('nsz' is required).
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test1_reassoc(float %arg) {
|
|
|
|
; CHECK-LABEL: @test1_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[T1:%.*]] = fsub reassoc float -1.200000e+01, [[ARG:%.*]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fadd reassoc float [[T1]], 1.200000e+01
|
|
|
|
; CHECK-NEXT: ret float [[T2]]
|
|
|
|
;
|
|
|
|
%t1 = fsub reassoc float -1.200000e+01, %arg
|
|
|
|
%t2 = fadd reassoc float %t1, 1.200000e+01
|
|
|
|
ret float %t2
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test2(float %reg109, float %reg1111) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[REG115:%.*]] = fadd float [[REG109:%.*]], -3.000000e+01
|
|
|
|
; CHECK-NEXT: [[REG116:%.*]] = fadd float [[REG115]], [[REG1111:%.*]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: [[REG117:%.*]] = fadd float [[REG116]], 3.000000e+01
|
|
|
|
; CHECK-NEXT: ret float [[REG117]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%reg115 = fadd float %reg109, -3.000000e+01
|
|
|
|
%reg116 = fadd float %reg115, %reg1111
|
|
|
|
%reg117 = fadd float %reg116, 3.000000e+01
|
|
|
|
ret float %reg117
|
|
|
|
}
|
|
|
|
|
|
|
|
define float @test3(float %reg109, float %reg1111) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test3(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[REG117:%.*]] = fadd fast float [[REG109:%.*]], [[REG1111:%.*]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[REG117]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%reg115 = fadd fast float %reg109, -3.000000e+01
|
|
|
|
%reg116 = fadd fast float %reg115, %reg1111
|
|
|
|
%reg117 = fadd fast float %reg116, 3.000000e+01
|
|
|
|
ret float %reg117
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test3_reassoc(float %reg109, float %reg1111) {
|
|
|
|
; CHECK-LABEL: @test3_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[REG115:%.*]] = fadd reassoc float [[REG109:%.*]], -3.000000e+01
|
|
|
|
; CHECK-NEXT: [[REG116:%.*]] = fadd reassoc float [[REG115]], [[REG1111:%.*]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[REG117:%.*]] = fadd reassoc float [[REG116]], 3.000000e+01
|
|
|
|
; CHECK-NEXT: ret float [[REG117]]
|
|
|
|
;
|
|
|
|
%reg115 = fadd reassoc float %reg109, -3.000000e+01
|
|
|
|
%reg116 = fadd reassoc float %reg115, %reg1111
|
|
|
|
%reg117 = fadd reassoc float %reg116, 3.000000e+01
|
|
|
|
ret float %reg117
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
@fe = external global float
|
|
|
|
@fa = external global float
|
|
|
|
@fb = external global float
|
|
|
|
@fc = external global float
|
|
|
|
@ff = external global float
|
|
|
|
|
|
|
|
define void @test4() {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test4(
|
|
|
|
; CHECK-NEXT: [[A:%.*]] = load float, float* @fa, align 4
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = load float, float* @fb, align 4
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = load float, float* @fc, align 4
|
|
|
|
; CHECK-NEXT: [[T1:%.*]] = fadd fast float [[B]], [[A]]
|
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fadd fast float [[T1]], [[C]]
|
|
|
|
; CHECK-NEXT: store float [[T2]], float* @fe, align 4
|
|
|
|
; CHECK-NEXT: store float [[T2]], float* @ff, align 4
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
;
|
2015-02-28 05:17:42 +08:00
|
|
|
%A = load float, float* @fa
|
|
|
|
%B = load float, float* @fb
|
|
|
|
%C = load float, float* @fc
|
2014-08-14 23:23:01 +08:00
|
|
|
%t1 = fadd fast float %A, %B
|
|
|
|
%t2 = fadd fast float %t1, %C
|
|
|
|
%t3 = fadd fast float %C, %A
|
|
|
|
%t4 = fadd fast float %t3, %B
|
|
|
|
; e = (a+b)+c;
|
|
|
|
store float %t2, float* @fe
|
|
|
|
; f = (a+c)+b
|
|
|
|
store float %t4, float* @ff
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test5() {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test5(
|
|
|
|
; CHECK-NEXT: [[A:%.*]] = load float, float* @fa, align 4
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = load float, float* @fb, align 4
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = load float, float* @fc, align 4
|
|
|
|
; CHECK-NEXT: [[T1:%.*]] = fadd fast float [[B]], [[A]]
|
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fadd fast float [[T1]], [[C]]
|
|
|
|
; CHECK-NEXT: store float [[T2]], float* @fe, align 4
|
|
|
|
; CHECK-NEXT: store float [[T2]], float* @ff, align 4
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
;
|
2015-02-28 05:17:42 +08:00
|
|
|
%A = load float, float* @fa
|
|
|
|
%B = load float, float* @fb
|
|
|
|
%C = load float, float* @fc
|
2014-08-14 23:23:01 +08:00
|
|
|
%t1 = fadd fast float %A, %B
|
|
|
|
%t2 = fadd fast float %t1, %C
|
|
|
|
%t3 = fadd fast float %C, %A
|
|
|
|
%t4 = fadd fast float %t3, %B
|
|
|
|
; e = c+(a+b)
|
|
|
|
store float %t2, float* @fe
|
|
|
|
; f = (c+a)+b
|
|
|
|
store float %t4, float* @ff
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test6() {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test6(
|
|
|
|
; CHECK-NEXT: [[A:%.*]] = load float, float* @fa, align 4
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = load float, float* @fb, align 4
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = load float, float* @fc, align 4
|
|
|
|
; CHECK-NEXT: [[T1:%.*]] = fadd fast float [[B]], [[A]]
|
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fadd fast float [[T1]], [[C]]
|
|
|
|
; CHECK-NEXT: store float [[T2]], float* @fe, align 4
|
|
|
|
; CHECK-NEXT: store float [[T2]], float* @ff, align 4
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
;
|
2015-02-28 05:17:42 +08:00
|
|
|
%A = load float, float* @fa
|
|
|
|
%B = load float, float* @fb
|
|
|
|
%C = load float, float* @fc
|
2014-08-14 23:23:01 +08:00
|
|
|
%t1 = fadd fast float %B, %A
|
|
|
|
%t2 = fadd fast float %t1, %C
|
|
|
|
%t3 = fadd fast float %C, %A
|
|
|
|
%t4 = fadd fast float %t3, %B
|
|
|
|
; e = c+(b+a)
|
|
|
|
store float %t2, float* @fe
|
|
|
|
; f = (c+a)+b
|
|
|
|
store float %t4, float* @ff
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define float @test7(float %A, float %B, float %C) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test7(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float [[C:%.*]], [[B:%.*]]
|
|
|
|
; CHECK-NEXT: [[REASS_MUL2:%.*]] = fmul fast float [[A:%.*]], [[A]]
|
|
|
|
; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_MUL2]], [[REASS_ADD1]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[REASS_MUL]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%aa = fmul fast float %A, %A
|
|
|
|
%aab = fmul fast float %aa, %B
|
|
|
|
%ac = fmul fast float %A, %C
|
|
|
|
%aac = fmul fast float %ac, %A
|
|
|
|
%r = fadd fast float %aab, %aac
|
|
|
|
ret float %r
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test7_reassoc(float %A, float %B, float %C) {
|
|
|
|
; CHECK-LABEL: @test7_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[AA:%.*]] = fmul reassoc float [[A:%.*]], [[A]]
|
|
|
|
; CHECK-NEXT: [[AAB:%.*]] = fmul reassoc float [[AA]], [[B:%.*]]
|
2018-03-02 08:14:51 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc float [[A]], [[A]]
|
|
|
|
; CHECK-NEXT: [[AAC:%.*]] = fmul reassoc float [[TMP1]], [[C:%.*]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[R:%.*]] = fadd reassoc float [[AAB]], [[AAC]]
|
|
|
|
; CHECK-NEXT: ret float [[R]]
|
|
|
|
;
|
|
|
|
%aa = fmul reassoc float %A, %A
|
|
|
|
%aab = fmul reassoc float %aa, %B
|
|
|
|
%ac = fmul reassoc float %A, %C
|
|
|
|
%aac = fmul reassoc float %ac, %A
|
|
|
|
%r = fadd reassoc float %aab, %aac
|
|
|
|
ret float %r
|
|
|
|
}
|
|
|
|
|
|
|
|
; (-X)*Y + Z -> Z-X*Y
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test8(float %X, float %Y, float %Z) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test8(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fmul fast float [[Y:%.*]], [[X:%.*]]
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = fsub fast float [[Z:%.*]], [[A]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[C]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%A = fsub fast float 0.0, %X
|
|
|
|
%B = fmul fast float %A, %Y
|
|
|
|
%C = fadd fast float %B, %Z
|
|
|
|
ret float %C
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test8_reassoc(float %X, float %Y, float %Z) {
|
|
|
|
; CHECK-LABEL: @test8_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fsub reassoc float 0.000000e+00, [[X:%.*]]
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fmul reassoc float [[A]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = fadd reassoc float [[B]], [[Z:%.*]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: ret float [[C]]
|
|
|
|
;
|
|
|
|
%A = fsub reassoc float 0.0, %X
|
|
|
|
%B = fmul reassoc float %A, %Y
|
|
|
|
%C = fadd reassoc float %B, %Z
|
|
|
|
ret float %C
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test9(float %X) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test9(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float [[X:%.*]], 9.400000e+01
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[FACTOR]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%Y = fmul fast float %X, 4.700000e+01
|
|
|
|
%Z = fadd fast float %Y, %Y
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
2018-04-15 03:18:28 +08:00
|
|
|
; Check again with 'reassoc' and 'nsz' ('nsz' not technically required).
|
|
|
|
define float @test9_reassoc_nsz(float %X) {
|
|
|
|
; CHECK-LABEL: @test9_reassoc_nsz(
|
|
|
|
; CHECK-NEXT: [[FACTOR:%.*]] = fmul reassoc nsz float [[X:%.*]], 9.400000e+01
|
|
|
|
; CHECK-NEXT: ret float [[FACTOR]]
|
|
|
|
;
|
|
|
|
%Y = fmul reassoc nsz float %X, 4.700000e+01
|
|
|
|
%Z = fadd reassoc nsz float %Y, %Y
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
|
|
|
; TODO: This doesn't require 'nsz'. It should fold to X * 94.0
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test9_reassoc(float %X) {
|
|
|
|
; CHECK-LABEL: @test9_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[Y:%.*]] = fmul reassoc float [[X:%.*]], 4.700000e+01
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[Z:%.*]] = fadd reassoc float [[Y]], [[Y]]
|
|
|
|
; CHECK-NEXT: ret float [[Z]]
|
|
|
|
;
|
|
|
|
%Y = fmul reassoc float %X, 4.700000e+01
|
|
|
|
%Z = fadd reassoc float %Y, %Y
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
2018-04-15 03:18:28 +08:00
|
|
|
; Side note: (x + x + x) and (3*x) each have only a single rounding. So
|
|
|
|
; transforming x+x+x to 3*x is always safe, even without any FMF.
|
|
|
|
; To avoid that special-case, we have the addition of 'x' four times, here.
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test10(float %X) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test10(
|
2018-04-15 03:18:28 +08:00
|
|
|
; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float [[X:%.*]], 4.000000e+00
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[FACTOR]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%Y = fadd fast float %X ,%X
|
|
|
|
%Z = fadd fast float %Y, %X
|
2018-04-15 03:18:28 +08:00
|
|
|
%W = fadd fast float %Z, %X
|
|
|
|
ret float %W
|
|
|
|
}
|
|
|
|
|
|
|
|
; Check again with 'reassoc' and 'nsz' ('nsz' not technically required).
|
|
|
|
define float @test10_reassoc_nsz(float %X) {
|
|
|
|
; CHECK-LABEL: @test10_reassoc_nsz(
|
|
|
|
; CHECK-NEXT: [[FACTOR:%.*]] = fmul reassoc nsz float [[X:%.*]], 4.000000e+00
|
|
|
|
; CHECK-NEXT: ret float [[FACTOR]]
|
|
|
|
;
|
|
|
|
%Y = fadd reassoc nsz float %X ,%X
|
|
|
|
%Z = fadd reassoc nsz float %Y, %X
|
|
|
|
%W = fadd reassoc nsz float %Z, %X
|
|
|
|
ret float %W
|
2014-08-14 23:23:01 +08:00
|
|
|
}
|
|
|
|
|
2018-04-15 03:18:28 +08:00
|
|
|
; TODO: This doesn't require 'nsz'. It should fold to 4 * x
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test10_reassoc(float %X) {
|
|
|
|
; CHECK-LABEL: @test10_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[Y:%.*]] = fadd reassoc float [[X:%.*]], [[X]]
|
|
|
|
; CHECK-NEXT: [[Z:%.*]] = fadd reassoc float [[Y]], [[X]]
|
2018-04-15 03:18:28 +08:00
|
|
|
; CHECK-NEXT: [[W:%.*]] = fadd reassoc float [[Z]], [[X]]
|
|
|
|
; CHECK-NEXT: ret float [[W]]
|
2017-11-14 01:29:11 +08:00
|
|
|
;
|
|
|
|
%Y = fadd reassoc float %X ,%X
|
|
|
|
%Z = fadd reassoc float %Y, %X
|
2018-04-15 03:18:28 +08:00
|
|
|
%W = fadd reassoc float %Z, %X
|
|
|
|
ret float %W
|
2017-11-14 01:29:11 +08:00
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test11(float %W) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test11(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float [[W:%.*]], 3.810000e+02
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[FACTOR]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%X = fmul fast float %W, 127.0
|
|
|
|
%Y = fadd fast float %X ,%X
|
|
|
|
%Z = fadd fast float %Y, %X
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
2018-04-15 03:18:28 +08:00
|
|
|
; Check again using the minimal subset of FMF.
|
|
|
|
; Check again with 'reassoc' and 'nsz' ('nsz' not technically required).
|
|
|
|
define float @test11_reassoc_nsz(float %W) {
|
|
|
|
; CHECK-LABEL: @test11_reassoc_nsz(
|
|
|
|
; CHECK-NEXT: [[FACTOR:%.*]] = fmul reassoc nsz float [[W:%.*]], 3.810000e+02
|
|
|
|
; CHECK-NEXT: ret float [[FACTOR]]
|
|
|
|
;
|
|
|
|
%X = fmul reassoc nsz float %W, 127.0
|
|
|
|
%Y = fadd reassoc nsz float %X ,%X
|
|
|
|
%Z = fadd reassoc nsz float %Y, %X
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
|
|
|
; TODO: This doesn't require 'nsz'. It should fold to W*381.0.
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test11_reassoc(float %W) {
|
|
|
|
; CHECK-LABEL: @test11_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[X:%.*]] = fmul reassoc float [[W:%.*]], 1.270000e+02
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[Y:%.*]] = fadd reassoc float [[X]], [[X]]
|
|
|
|
; CHECK-NEXT: [[Z:%.*]] = fadd reassoc float [[X]], [[Y]]
|
|
|
|
; CHECK-NEXT: ret float [[Z]]
|
|
|
|
;
|
|
|
|
%X = fmul reassoc float %W, 127.0
|
|
|
|
%Y = fadd reassoc float %X ,%X
|
|
|
|
%Z = fadd reassoc float %Y, %X
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test12(float %X) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test12(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast float [[X:%.*]], -3.000000e+00
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: [[Z:%.*]] = fadd fast float [[FACTOR]], 6.000000e+00
|
|
|
|
; CHECK-NEXT: ret float [[Z]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%A = fsub fast float 1.000000e+00, %X
|
|
|
|
%B = fsub fast float 2.000000e+00, %X
|
|
|
|
%C = fsub fast float 3.000000e+00, %X
|
|
|
|
%Y = fadd fast float %A ,%B
|
|
|
|
%Z = fadd fast float %Y, %C
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
2018-04-15 03:18:28 +08:00
|
|
|
; Check again with 'reassoc' and 'nsz' ('nsz' not technically required).
|
|
|
|
define float @test12_reassoc_nsz(float %X) {
|
|
|
|
; CHECK-LABEL: @test12_reassoc_nsz(
|
|
|
|
; CHECK-NEXT: [[FACTOR:%.*]] = fmul reassoc nsz float [[X:%.*]], 3.000000e+00
|
|
|
|
; CHECK-NEXT: [[Z:%.*]] = fsub reassoc nsz float 6.000000e+00, [[FACTOR]]
|
|
|
|
; CHECK-NEXT: ret float [[Z]]
|
|
|
|
;
|
|
|
|
%A = fsub reassoc nsz float 1.000000e+00, %X
|
|
|
|
%B = fsub reassoc nsz float 2.000000e+00, %X
|
|
|
|
%C = fsub reassoc nsz float 3.000000e+00, %X
|
|
|
|
%Y = fadd reassoc nsz float %A ,%B
|
|
|
|
%Z = fadd reassoc nsz float %Y, %C
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
|
|
|
; TODO: This doesn't require 'nsz'. It should fold to (6.0 - 3.0*x)
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test12_reassoc(float %X) {
|
|
|
|
; CHECK-LABEL: @test12_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fsub reassoc float 1.000000e+00, [[X:%.*]]
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fsub reassoc float 2.000000e+00, [[X]]
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = fsub reassoc float 3.000000e+00, [[X]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[Y:%.*]] = fadd reassoc float [[A]], [[B]]
|
|
|
|
; CHECK-NEXT: [[Z:%.*]] = fadd reassoc float [[C]], [[Y]]
|
|
|
|
; CHECK-NEXT: ret float [[Z]]
|
|
|
|
;
|
|
|
|
%A = fsub reassoc float 1.000000e+00, %X
|
|
|
|
%B = fsub reassoc float 2.000000e+00, %X
|
|
|
|
%C = fsub reassoc float 3.000000e+00, %X
|
|
|
|
%Y = fadd reassoc float %A ,%B
|
|
|
|
%Z = fadd reassoc float %Y, %C
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test13(float %X1, float %X2, float %X3) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test13(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[REASS_ADD:%.*]] = fsub fast float [[X3:%.*]], [[X2:%.*]]
|
|
|
|
; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD]], [[X1:%.*]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[REASS_MUL]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%A = fsub fast float 0.000000e+00, %X1
|
|
|
|
%B = fmul fast float %A, %X2 ; -X1*X2
|
|
|
|
%C = fmul fast float %X1, %X3 ; X1*X3
|
|
|
|
%D = fadd fast float %B, %C ; -X1*X2 + X1*X3 -> X1*(X3-X2)
|
|
|
|
ret float %D
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test13_reassoc(float %X1, float %X2, float %X3) {
|
|
|
|
; CHECK-LABEL: @test13_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[A:%.*]] = fsub reassoc float 0.000000e+00, [[X1:%.*]]
|
|
|
|
; CHECK-NEXT: [[B:%.*]] = fmul reassoc float [[A]], [[X2:%.*]]
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = fmul reassoc float [[X1]], [[X3:%.*]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[D:%.*]] = fadd reassoc float [[B]], [[C]]
|
|
|
|
; CHECK-NEXT: ret float [[D]]
|
|
|
|
;
|
|
|
|
%A = fsub reassoc float 0.000000e+00, %X1
|
|
|
|
%B = fmul reassoc float %A, %X2 ; -X1*X2
|
|
|
|
%C = fmul reassoc float %X1, %X3 ; X1*X3
|
|
|
|
%D = fadd reassoc float %B, %C ; -X1*X2 + X1*X3 -> X1*(X3-X2)
|
|
|
|
ret float %D
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test14(float %X1, float %X2) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test14(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fsub fast float [[X1:%.*]], [[X2:%.*]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], 4.700000e+01
|
|
|
|
; CHECK-NEXT: ret float [[TMP2]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%B = fmul fast float %X1, 47. ; X1*47
|
|
|
|
%C = fmul fast float %X2, -47. ; X2*-47
|
|
|
|
%D = fadd fast float %B, %C ; X1*47 + X2*-47 -> 47*(X1-X2)
|
|
|
|
ret float %D
|
|
|
|
}
|
|
|
|
|
2018-04-15 03:18:28 +08:00
|
|
|
; (x1 * 47) + (x2 * -47) => (x1 - x2) * 47
|
|
|
|
; Check again with 'reassoc' and 'nsz' ('nsz' not technically required).
|
|
|
|
define float @test14_reassoc_nsz(float %X1, float %X2) {
|
|
|
|
; CHECK-LABEL: @test14_reassoc_nsz(
|
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float [[X1:%.*]], [[X2:%.*]]
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz float [[TMP1]], 4.700000e+01
|
|
|
|
; CHECK-NEXT: ret float [[TMP2]]
|
|
|
|
;
|
|
|
|
%B = fmul reassoc nsz float %X1, 47. ; X1*47
|
|
|
|
%C = fmul reassoc nsz float %X2, -47. ; X2*-47
|
|
|
|
%D = fadd reassoc nsz float %B, %C ; X1*47 + X2*-47 -> 47*(X1-X2)
|
|
|
|
ret float %D
|
|
|
|
}
|
|
|
|
|
|
|
|
; TODO: This doesn't require 'nsz'. It should fold to ((x1 - x2) * 47.0)
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test14_reassoc(float %X1, float %X2) {
|
|
|
|
; CHECK-LABEL: @test14_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[B:%.*]] = fmul reassoc float [[X1:%.*]], 4.700000e+01
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = fmul reassoc float [[X2:%.*]], 4.700000e+01
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[D1:%.*]] = fsub reassoc float [[B]], [[C]]
|
|
|
|
; CHECK-NEXT: ret float [[D1]]
|
|
|
|
;
|
|
|
|
%B = fmul reassoc float %X1, 47. ; X1*47
|
|
|
|
%C = fmul reassoc float %X2, -47. ; X2*-47
|
|
|
|
%D = fadd reassoc float %B, %C ; X1*47 + X2*-47 -> 47*(X1-X2)
|
|
|
|
ret float %D
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test15(float %arg) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test15(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fmul fast float [[ARG:%.*]], 1.440000e+02
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[T2]]
|
|
|
|
;
|
|
|
|
%t1 = fmul fast float 1.200000e+01, %arg
|
|
|
|
%t2 = fmul fast float %t1, 1.200000e+01
|
|
|
|
ret float %t2
|
2014-08-14 23:23:01 +08:00
|
|
|
}
|
|
|
|
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test15_reassoc(float %arg) {
|
|
|
|
; CHECK-LABEL: @test15_reassoc(
|
2018-03-02 08:14:51 +08:00
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fmul reassoc float [[ARG:%.*]], 1.440000e+02
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: ret float [[T2]]
|
|
|
|
;
|
|
|
|
%t1 = fmul reassoc float 1.200000e+01, %arg
|
|
|
|
%t2 = fmul reassoc float %t1, 1.200000e+01
|
|
|
|
ret float %t2
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
; (b+(a+1234))+-a -> b+1234
|
|
|
|
define float @test16(float %b, float %a) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test16(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fadd fast float [[B:%.*]], 1.234000e+03
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[TMP1]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%1 = fadd fast float %a, 1234.0
|
|
|
|
%2 = fadd fast float %b, %1
|
|
|
|
%3 = fsub fast float 0.0, %a
|
|
|
|
%4 = fadd fast float %2, %3
|
|
|
|
ret float %4
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test16_reassoc(float %b, float %a) {
|
|
|
|
; CHECK-LABEL: @test16_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fadd reassoc float [[A:%.*]], 1.234000e+03
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = fadd reassoc float [[TMP1]], [[B:%.*]]
|
|
|
|
; CHECK-NEXT: [[TMP3:%.*]] = fsub reassoc float 0.000000e+00, [[A]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[TMP4:%.*]] = fadd reassoc float [[TMP3]], [[TMP2]]
|
|
|
|
; CHECK-NEXT: ret float [[TMP4]]
|
|
|
|
;
|
|
|
|
%1 = fadd reassoc float %a, 1234.0
|
|
|
|
%2 = fadd reassoc float %b, %1
|
|
|
|
%3 = fsub reassoc float 0.0, %a
|
|
|
|
%4 = fadd reassoc float %2, %3
|
|
|
|
ret float %4
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z.
|
|
|
|
|
|
|
|
define float @test17(float %a, float %b, float %z) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test17(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[E:%.*]] = fmul fast float [[A:%.*]], 1.234500e+04
|
|
|
|
; CHECK-NEXT: [[F:%.*]] = fmul fast float [[E]], [[B:%.*]]
|
|
|
|
; CHECK-NEXT: [[G:%.*]] = fmul fast float [[F]], [[Z:%.*]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[G]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%c = fsub fast float 0.000000e+00, %z
|
|
|
|
%d = fmul fast float %a, %b
|
|
|
|
%e = fmul fast float %c, %d
|
|
|
|
%f = fmul fast float %e, 1.234500e+04
|
|
|
|
%g = fsub fast float 0.000000e+00, %f
|
|
|
|
ret float %g
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test17_reassoc(float %a, float %b, float %z) {
|
|
|
|
; CHECK-LABEL: @test17_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[C:%.*]] = fsub reassoc float 0.000000e+00, [[Z:%.*]]
|
|
|
|
; CHECK-NEXT: [[D:%.*]] = fmul reassoc float [[A:%.*]], [[B:%.*]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[E:%.*]] = fmul reassoc float [[D]], [[C]]
|
|
|
|
; CHECK-NEXT: [[F:%.*]] = fmul reassoc float [[E]], 1.234500e+04
|
|
|
|
; CHECK-NEXT: [[G:%.*]] = fsub reassoc float 0.000000e+00, [[F]]
|
|
|
|
; CHECK-NEXT: ret float [[G]]
|
|
|
|
;
|
|
|
|
%c = fsub reassoc float 0.000000e+00, %z
|
|
|
|
%d = fmul reassoc float %a, %b
|
|
|
|
%e = fmul reassoc float %c, %d
|
|
|
|
%f = fmul reassoc float %e, 1.234500e+04
|
|
|
|
%g = fsub reassoc float 0.000000e+00, %f
|
|
|
|
ret float %g
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
define float @test18(float %a, float %b, float %z) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test18(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[E:%.*]] = fmul fast float [[A:%.*]], 4.000000e+01
|
|
|
|
; CHECK-NEXT: [[F:%.*]] = fmul fast float [[E]], [[Z:%.*]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[F]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%d = fmul fast float %z, 4.000000e+01
|
|
|
|
%c = fsub fast float 0.000000e+00, %d
|
|
|
|
%e = fmul fast float %a, %c
|
|
|
|
%f = fsub fast float 0.000000e+00, %e
|
|
|
|
ret float %f
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test18_reassoc(float %a, float %b, float %z) {
|
|
|
|
; CHECK-LABEL: @test18_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[D:%.*]] = fmul reassoc float [[Z:%.*]], 4.000000e+01
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[C:%.*]] = fsub reassoc float 0.000000e+00, [[D]]
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[E:%.*]] = fmul reassoc float [[C]], [[A:%.*]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[F:%.*]] = fsub reassoc float 0.000000e+00, [[E]]
|
|
|
|
; CHECK-NEXT: ret float [[F]]
|
|
|
|
;
|
|
|
|
%d = fmul reassoc float %z, 4.000000e+01
|
|
|
|
%c = fsub reassoc float 0.000000e+00, %d
|
|
|
|
%e = fmul reassoc float %a, %c
|
|
|
|
%f = fsub reassoc float 0.000000e+00, %e
|
|
|
|
ret float %f
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
; With sub reassociation, constant folding can eliminate the 12 and -12 constants.
|
|
|
|
define float @test19(float %A, float %B) {
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-LABEL: @test19(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[Z:%.*]] = fsub fast float [[A:%.*]], [[B:%.*]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[Z]]
|
|
|
|
;
|
2014-08-14 23:23:01 +08:00
|
|
|
%X = fadd fast float -1.200000e+01, %A
|
|
|
|
%Y = fsub fast float %X, %B
|
|
|
|
%Z = fadd fast float %Y, 1.200000e+01
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:29:11 +08:00
|
|
|
define float @test19_reassoc(float %A, float %B) {
|
|
|
|
; CHECK-LABEL: @test19_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[X:%.*]] = fadd reassoc float [[A:%.*]], -1.200000e+01
|
|
|
|
; CHECK-NEXT: [[Y:%.*]] = fsub reassoc float [[X]], [[B:%.*]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: [[Z:%.*]] = fadd reassoc float [[Y]], 1.200000e+01
|
|
|
|
; CHECK-NEXT: ret float [[Z]]
|
|
|
|
;
|
|
|
|
%X = fadd reassoc float -1.200000e+01, %A
|
|
|
|
%Y = fsub reassoc float %X, %B
|
|
|
|
%Z = fadd reassoc float %Y, 1.200000e+01
|
|
|
|
ret float %Z
|
|
|
|
}
|
|
|
|
|
2014-08-14 23:23:01 +08:00
|
|
|
; With sub reassociation, constant folding can eliminate the uses of %a.
|
|
|
|
define float @test20(float %a, float %b, float %c) nounwind {
|
|
|
|
; FIXME: Should be able to generate the below, which may expose more
|
|
|
|
; opportunites for FAdd reassociation.
|
|
|
|
; %sum = fadd fast float %c, %b
|
2017-11-10 02:14:24 +08:00
|
|
|
; %t7 = fsub fast float 0, %sum
|
|
|
|
; CHECK-LABEL: @test20(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[B_NEG:%.*]] = fsub fast float -0.000000e+00, [[B:%.*]]
|
|
|
|
; CHECK-NEXT: [[T7:%.*]] = fsub fast float [[B_NEG]], [[C:%.*]]
|
2017-11-10 02:14:24 +08:00
|
|
|
; CHECK-NEXT: ret float [[T7]]
|
|
|
|
;
|
|
|
|
%t3 = fsub fast float %a, %b
|
|
|
|
%t5 = fsub fast float %t3, %c
|
|
|
|
%t7 = fsub fast float %t5, %a
|
|
|
|
ret float %t7
|
2014-08-14 23:23:01 +08:00
|
|
|
}
|
2017-11-14 01:29:11 +08:00
|
|
|
|
|
|
|
define float @test20_reassoc(float %a, float %b, float %c) nounwind {
|
|
|
|
; CHECK-LABEL: @test20_reassoc(
|
2018-03-02 07:41:03 +08:00
|
|
|
; CHECK-NEXT: [[T3:%.*]] = fsub reassoc float [[A:%.*]], [[B:%.*]]
|
|
|
|
; CHECK-NEXT: [[T5:%.*]] = fsub reassoc float [[T3]], [[C:%.*]]
|
|
|
|
; CHECK-NEXT: [[T7:%.*]] = fsub reassoc float [[T5]], [[A]]
|
2017-11-14 01:29:11 +08:00
|
|
|
; CHECK-NEXT: ret float [[T7]]
|
|
|
|
;
|
|
|
|
%t3 = fsub reassoc float %a, %b
|
|
|
|
%t5 = fsub reassoc float %t3, %c
|
|
|
|
%t7 = fsub reassoc float %t5, %a
|
|
|
|
ret float %t7
|
|
|
|
}
|
|
|
|
|