llvm.org GIT mirror llvm / 2d534b8
[AArch64][MachineCombine] Fold FNMUL+FSUB -> FNMADD. Differential Revision: http://reviews.llvm.org/D33101. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302822 91177308-0d34-0410-b5e6-96231b3b80d8 Chad Rosier 2 years ago
3 changed file(s) with 53 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
4747 FMULADDD_OP2,
4848 FMULSUBD_OP1,
4949 FMULSUBD_OP2,
50 FNMULSUBS_OP1,
51 FNMULSUBD_OP1,
5052 FMLAv1i32_indexed_OP1,
5153 FMLAv1i32_indexed_OP2,
5254 FMLAv1i64_indexed_OP1,
34263426 Patterns.push_back(MachineCombinerPattern::FMLSv1i32_indexed_OP2);
34273427 Found = true;
34283428 }
3429 if (canCombineWithFMUL(MBB, Root.getOperand(1), AArch64::FNMULSrr)) {
3430 Patterns.push_back(MachineCombinerPattern::FNMULSUBS_OP1);
3431 Found = true;
3432 }
34293433 break;
34303434 case AArch64::FSUBDrr:
34313435 if (canCombineWithFMUL(MBB, Root.getOperand(1), AArch64::FMULDrr)) {
34383442 } else if (canCombineWithFMUL(MBB, Root.getOperand(2),
34393443 AArch64::FMULv1i64_indexed)) {
34403444 Patterns.push_back(MachineCombinerPattern::FMLSv1i64_indexed_OP2);
3445 Found = true;
3446 }
3447 if (canCombineWithFMUL(MBB, Root.getOperand(1), AArch64::FNMULDrr)) {
3448 Patterns.push_back(MachineCombinerPattern::FNMULSUBD_OP1);
34413449 Found = true;
34423450 }
34433451 break;
34943502 case MachineCombinerPattern::FMULADDD_OP2:
34953503 case MachineCombinerPattern::FMULSUBD_OP1:
34963504 case MachineCombinerPattern::FMULSUBD_OP2:
3505 case MachineCombinerPattern::FNMULSUBS_OP1:
3506 case MachineCombinerPattern::FNMULSUBD_OP1:
34973507 case MachineCombinerPattern::FMLAv1i32_indexed_OP1:
34983508 case MachineCombinerPattern::FMLAv1i32_indexed_OP2:
34993509 case MachineCombinerPattern::FMLAv1i64_indexed_OP1:
39954005 MUL = genFusedMultiply(MF, MRI, TII, Root, InsInstrs, 1, Opc, RC);
39964006 break;
39974007 }
4008
4009 case MachineCombinerPattern::FNMULSUBS_OP1:
4010 case MachineCombinerPattern::FNMULSUBD_OP1: {
4011 // FNMUL I=A,B,0
4012 // FSUB R,I,C
4013 // ==> FNMADD R,A,B,C // = -A*B - C
4014 // --- Create(FNMADD);
4015 if (Pattern == MachineCombinerPattern::FNMULSUBS_OP1) {
4016 Opc = AArch64::FNMADDSrrr;
4017 RC = &AArch64::FPR32RegClass;
4018 } else {
4019 Opc = AArch64::FNMADDDrrr;
4020 RC = &AArch64::FPR64RegClass;
4021 }
4022 MUL = genFusedMultiply(MF, MRI, TII, Root, InsInstrs, 1, Opc, RC);
4023 break;
4024 }
4025
39984026 case MachineCombinerPattern::FMULSUBS_OP2:
39994027 case MachineCombinerPattern::FMULSUBD_OP2: {
40004028 // FMUL I=A,B,0
None ; RUN: llc < %s -O=3 -mtriple=arm64-apple-ios -mcpu=cyclone -enable-unsafe-fp-math | FileCheck %s
0 ; RUN: llc < %s -O3 -mtriple=arm64-apple-ios -enable-unsafe-fp-math | FileCheck %s
1 ; RUN: llc < %s -O3 -mtriple=arm64-apple-ios -fp-contract=fast | FileCheck %s
2
13 define void @foo_2d(double* %src) {
24 entry:
35 %arrayidx1 = getelementptr inbounds double, double* %src, i64 5
125127 for.end: ; preds = %for.body
126128 ret void
127129 }
130
131 ; CHECK-LABEL: test1:
132 ; CHECK: fnmadd s0, s0, s1, s2
133 define float @test1(float %a, float %b, float %c) {
134 entry:
135 %0 = fmul float %a, %b
136 %mul = fsub float -0.000000e+00, %0
137 %sub1 = fsub float %mul, %c
138 ret float %sub1
139 }
140
141 ; CHECK-LABEL: test2:
142 ; CHECK: fnmadd d0, d0, d1, d2
143 define double @test2(double %a, double %b, double %c) {
144 entry:
145 %0 = fmul double %a, %b
146 %mul = fsub double -0.000000e+00, %0
147 %sub1 = fsub double %mul, %c
148 ret double %sub1
149 }