[InstCombine] factor difference-of-squares to reduce multiplication
authorSanjay Patel <spatel@rotateright.com>
Tue, 17 Jan 2023 19:37:18 +0000 (14:37 -0500)
committerSanjay Patel <spatel@rotateright.com>
Tue, 17 Jan 2023 19:58:40 +0000 (14:58 -0500)
commit68c197f07eeae71b9b772c9e0c3b846c7025b332
tree0c012939707adc59259d4fd42f40158ee829ea83
parentbf44905183efe54599956e308a236635c9b46e71
[InstCombine] factor difference-of-squares to reduce multiplication

(X * X) - (Y * Y) --> (X + Y) * (X - Y)
https://alive2.llvm.org/ce/z/BAuRCf

The no-wrap propagation could be relaxed in some cases,
but there does not seem to be an obvious rule for that.
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/sub.ll