[PATCH] D75634: [ConstantFolding] Accept FoldedOps cache as parameter

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 12:57:12 PST 2020


nikic created this revision.
nikic added reviewers: efriedma, spatel, lebedev.ri.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

InstCombine internally caches constant operands that it folds. ConstantFolding also internally caches folded operands, but does so only on the "second level": The direct operands of an instruction/constant are not cached, but the operands of the operands are. Presumably that's an oversight...

This patch allows passing in the folded operand cache as an extra parameter, and changes the ConstantFoldConstant API to also look up from it / write to it by itself. That way all users handle caching correctly, and the cache can be shared across calls (done only in InstCombine for now).

In particular this will also avoid duplicate constant folding between ConstantFoldInstruction and operand constant folding in InstCombine. I haven't run into this as a perf problem myself, but recently ran across D18155 <https://reviews.llvm.org/D18155>, which did identify this as a performance problem for some types of code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75634

Files:
  include/llvm/Analysis/ConstantFolding.h
  lib/Analysis/ConstantFolding.cpp
  lib/Transforms/InstCombine/InstructionCombining.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75634.248281.patch
Type: text/x-patch
Size: 7788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200304/4d8ecc31/attachment-0001.bin>


More information about the llvm-commits mailing list