Commit e60f49e
committed
[RISCV] Undo fneg (fmul x, y) -> fmul x, (fneg y) transform
InstCombine will hoist an fneg through an fmul, but not for fadd/fsub.
This prevents us from matching fmsub and fnmadd in some cases.
This patch adds a DAG combine to undo this in InstCombine, which helps some hot loops in 508.namd_r:
```diff
@@ -983,18 +983,15 @@
fld ft2, 48(a5)
fld ft3, 64(a5)
fld ft4, 72(a5)
- fneg.d fa0, fa0
- fneg.d ft0, ft0
- fneg.d ft2, ft2
fmul.d fa3, ft5, fa3
fmul.d fa0, fa3, fa0
fmul.d ft0, fa3, ft0
fmul.d fa3, fa3, ft2
fld ft2, 0(s1)
fmul.d fa4, ft5, fa4
- fmadd.d fa2, fa4, fa2, fa0
- fmadd.d ft6, fa4, ft6, ft0
- fmadd.d fa4, fa4, ft1, fa3
+ fmsub.d fa2, fa4, fa2, fa0
+ fmsub.d ft6, fa4, ft6, ft0
+ fmsub.d fa4, fa4, ft1, fa3
```
This gives a [1.77% improvement in both instruction count and runtime on 508.namd_r](https://lnt.lukelau.me/db_default/v4/nts/profile/1/1022/1021)
This also causes some more fnegs to be sunk after a bitcast to integer, so they're now done as xor. From glancing at some of the schedules for WriteFSGN my guess is that this is also profitable.1 parent 8d9e2be commit e60f49e
File tree
5 files changed
+95
-65
lines changed- llvm
- include/llvm/CodeGen
- lib/Target/RISCV
- test/CodeGen/RISCV
5 files changed
+95
-65
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1076 | 1076 | | |
1077 | 1077 | | |
1078 | 1078 | | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
1079 | 1083 | | |
1080 | 1084 | | |
1081 | 1085 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20250 | 20250 | | |
20251 | 20251 | | |
20252 | 20252 | | |
| 20253 | + | |
| 20254 | + | |
| 20255 | + | |
| 20256 | + | |
| 20257 | + | |
| 20258 | + | |
| 20259 | + | |
| 20260 | + | |
| 20261 | + | |
| 20262 | + | |
| 20263 | + | |
20253 | 20264 | | |
20254 | 20265 | | |
20255 | 20266 | | |
| |||
20260 | 20271 | | |
20261 | 20272 | | |
20262 | 20273 | | |
20263 | | - | |
20264 | 20274 | | |
20265 | 20275 | | |
20266 | 20276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
613 | 613 | | |
614 | 614 | | |
615 | 615 | | |
616 | | - | |
617 | | - | |
618 | | - | |
| 616 | + | |
| 617 | + | |
619 | 618 | | |
620 | 619 | | |
621 | 620 | | |
622 | 621 | | |
623 | | - | |
624 | 622 | | |
625 | | - | |
| 623 | + | |
626 | 624 | | |
627 | 625 | | |
628 | 626 | | |
629 | 627 | | |
630 | | - | |
631 | 628 | | |
632 | | - | |
| 629 | + | |
633 | 630 | | |
634 | 631 | | |
635 | 632 | | |
| |||
963 | 960 | | |
964 | 961 | | |
965 | 962 | | |
966 | | - | |
967 | | - | |
968 | | - | |
| 963 | + | |
| 964 | + | |
969 | 965 | | |
970 | 966 | | |
971 | 967 | | |
972 | 968 | | |
973 | | - | |
974 | 969 | | |
975 | | - | |
| 970 | + | |
976 | 971 | | |
977 | 972 | | |
978 | 973 | | |
979 | 974 | | |
980 | | - | |
981 | 975 | | |
982 | | - | |
| 976 | + | |
983 | 977 | | |
984 | 978 | | |
985 | 979 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
556 | | - | |
557 | | - | |
558 | | - | |
| 556 | + | |
| 557 | + | |
559 | 558 | | |
560 | 559 | | |
561 | 560 | | |
562 | 561 | | |
563 | | - | |
564 | 562 | | |
565 | | - | |
| 563 | + | |
566 | 564 | | |
567 | 565 | | |
568 | 566 | | |
| |||
847 | 845 | | |
848 | 846 | | |
849 | 847 | | |
850 | | - | |
851 | | - | |
852 | | - | |
| 848 | + | |
| 849 | + | |
853 | 850 | | |
854 | 851 | | |
855 | 852 | | |
856 | 853 | | |
857 | | - | |
858 | 854 | | |
859 | | - | |
| 855 | + | |
860 | 856 | | |
861 | 857 | | |
862 | 858 | | |
| |||
0 commit comments