[all-commits] [llvm/llvm-project] e496d3: [InstCombine] Drop one-use check in matchesSquareS...
konoongg via All-commits
all-commits at lists.llvm.org
Thu Oct 1 04:03:39 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: e496d3c1f3e60b27d8b016c0b36ecb89653ae38f
https://github.com/llvm/llvm-project/commit/e496d3c1f3e60b27d8b016c0b36ecb89653ae38f
Author: konoongg <120199924+konoongg at users.noreply.github.com>
Date: 2026-10-01 (Thu, 01 Oct 2026)
Changed paths:
M llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
M llvm/test/Transforms/InstCombine/add.ll
M llvm/test/Transforms/InstCombine/fadd.ll
Log Message:
-----------
[InstCombine] Drop one-use check in matchesSquareSum for (a*a) (#228020)
The pattern `(a * a) + (((a * 2) + b) * b)` is equivalent to `(a + b) *
(a + b)`. The current implementation requires the `a * a` subexpression
to have a single use, which prevents the fold when `a * a` is used
elsewhere. This check is unnecessary: we can still perform the fold and
keep the original `a * a` instruction for other uses.
For example, with an extra use of `a * a`:
%1 = mul i32 %a, %a
%2 = mul i32 %a, 2
%3 = add i32 %2, %b
%4 = mul i32 %3, %b
%5 = add i32 %4, %1
%6 = mul i32 %1, %1
After this change, InstCombine produces:
%1 = add i32 %a, %b
%2 = mul i32 %1, %1
%3 = mul i32 %a, %a
%4 = mul i32 %3, %3
This reduces the instruction count from 6 to 4, even though `a * a` is
now computed both explicitly (for the extra use) and implicitly as part
of `(a + b) * (a + b)`.
The same applies to the floating-point (fadd) variant. Both are
updated together.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list