((X >> C) - Y) + Z --> (Z - Y) + (X >> C)
Fix AArch part: #55714
Differential D136158
[AArch64] Adjust operand sequence for Add+Sub to combine more inline shift bcl5980 on Oct 18 2022, 4:22 AM. Authored by
Details ((X >> C) - Y) + Z --> (Z - Y) + (X >> C) Fix AArch part: #55714
Diff Detail Event TimelineComment Actions Have you tried testing this? I think it will get stuck in DAG combines. Otherwise the idea sounds good. Have you considered doing it for GlobalISel, or in a way that GlobalISel would also benefit? Comment Actions I haven't found any stuck in DAG combine local and it looks all of the premerge test is also passed: Which combination do you think will cause the dead loop in DAG combine with this patch? I can try to create a test for that. I can try to do it in GISel also in another patch later. Comment Actions Yes - the llvm regression tests are very much a subset of all the patterns that can come up in practice. I'm not sure what this is running into. Perhaps try and bootstrap or compiling the llvm-test-suite? Comment Actions Or can we do it on Machine IR(AArch64MIPeepholeOpt) to avoid dead loop and also GISel can get benefit? Comment Actions Thanks for finding the problem. This LGTM now.
I was wondering what to do about optimizations that can be shared between GISel and SDAG. AArch64MIPeepholeOpt often feels like the wrong place (MachineCombiner might be better for some optimizations like this one, but that currently doesn't scale very well). We don't really want to write them in the wrong place if they would be better as combines during ISel. For now at least this patch looks good. Comment Actions Building Firefox with LTO for any aarch64 target (linux, macos, windows) enters in some sort of infinite loop since this change (linking never ends). Comment Actions Reproducer: https://drive.google.com/file/d/1n7KPlKCydCgSdtnp6990Zn5_Yjbbss8L/view?usp=sharing (command in testcase/cmd) Comment Actions Is it link time infinite loop? Somehow this change doesn't have any effect on link stage. Comment Actions Thanks for reverting - I've also bisected down hangs to the same commit. For my case, it can be reproduced with https://martin.st/temp/aarch64-hang.c, with clang -target aarch64-linux-gnu -c -O2 aarch64-hang.c. Comment Actions In his case, he's doing LTO builds, so the compilation/codegen happens at link time. But my testcase might be smaller and easier to run. Comment Actions We also bisected hangs due to this (arm64 on all of android fuchsia ios mac). It looks like you have a bunch of reproducers already, but there's one more at https://bugs.chromium.org/p/chromium/issues/detail?id=1379286#c7 if you're interested (it's just a file from boringssl – we saw this hang on many files. I'd guess, but haven't checked, that doing a bootstrap build of clang on an arm64 box would also trigger this.) Thanks for the revert! Comment Actions I'm sorry but I don't know what is the bootstrap. Can you give me some suggestion for that? Where can I get a opensource bootstrap and build? Comment Actions Ah - it just means compiler the compiler with itself (on AArch64) and make sure it still passes all the tests. There are some details, including some handy cmake options in https://llvm.org/docs/AdvancedBuilds.html Comment Actions Thanks for the explaination. I have already build and test llvm itself on MacbookAir with M2 processor. |