[PATCH] D133369: [InstCombine] fold add+negate through select into sub

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 6 11:28:27 PDT 2022


spatel created this revision.
spatel added reviewers: craig.topper, RKSimon, nikic, efriedma.
Herald added subscribers: StephenFan, steven.zhang, hiraditya, kristof.beyls, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This transform came up as a potential DAGCombine in D133282 <https://reviews.llvm.org/D133282>, so I wanted to see how it escaped in IR too.

We do general folds in InstCombiner::SimplifySelectsFeedingBinaryOp() by checking if either arm of a select simplifies when the trailing binop is threaded into the select.

So as long as one side simplifies, it's a good fold to combine a negate and add into 1 subtract.

This is an example with a zero arm in the select:
https://alive2.llvm.org/ce/z/Hgu_Tj

And this models the tests with a cancelling 'not' op: 
https://alive2.llvm.org/ce/z/BuzVV_


https://reviews.llvm.org/D133369

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/add.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133369.458224.patch
Type: text/x-patch
Size: 8441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220906/c9144512/attachment-0001.bin>


More information about the llvm-commits mailing list