aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-08-21 12:02:54 +0200
committerGitHub <noreply@github.com>2024-08-21 12:02:54 +0200
commita105877646d68e48cdeeeadd9d1e075dc3c5d68d (patch)
treedbf12b014210e1485cbad0802e53ae976b37dab3 /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
parent297bb467acd31447d64f0540835127d50408e87d (diff)
downloadllvm-a105877646d68e48cdeeeadd9d1e075dc3c5d68d.zip
llvm-a105877646d68e48cdeeeadd9d1e075dc3c5d68d.tar.gz
llvm-a105877646d68e48cdeeeadd9d1e075dc3c5d68d.tar.bz2
[InstCombine] Remove some of the complexity-based canonicalization (#91185)
The idea behind this canonicalization is that it allows us to handle less patterns, because we know that some will be canonicalized away. This is indeed very useful to e.g. know that constants are always on the right. However, this is only useful if the canonicalization is actually reliable. This is the case for constants, but not for arguments: Moving these to the right makes it look like the "more complex" expression is guaranteed to be on the left, but this is not actually the case in practice. It fails as soon as you replace the argument with another instruction. The end result is that it looks like things correctly work in tests, while they actually don't. We use the "thwart complexity-based canonicalization" trick to handle this in tests, but it's often a challenge for new contributors to get this right, and based on the regressions this PR originally exposed, we clearly don't get this right in many cases. For this reason, I think that it's better to remove this complexity canonicalization. It will make it much easier to write tests for commuted cases and make sure that they are handled.
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 123f810..dd4a640 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -2719,8 +2719,10 @@ Instruction *InstCombinerImpl::hoistFNegAboveFMulFDiv(Value *FNegOp,
Instruction &FMFSource) {
Value *X, *Y;
if (match(FNegOp, m_FMul(m_Value(X), m_Value(Y)))) {
+ // Push into RHS which is more likely to simplify (const or another fneg).
+ // FIXME: It would be better to invert the transform.
return cast<Instruction>(Builder.CreateFMulFMF(
- Builder.CreateFNegFMF(X, &FMFSource), Y, &FMFSource));
+ X, Builder.CreateFNegFMF(Y, &FMFSource), &FMFSource));
}
if (match(FNegOp, m_FDiv(m_Value(X), m_Value(Y)))) {