This is an archive of the discontinued LLVM Phabricator instance.

[TTI] NFC: Change getIntImmCost[Inst|Intrin] to return InstructionCost
ClosedPublic

Authored by sdesmalen on Apr 15 2021, 7:22 AM.

Details

Summary

This patch migrates the TTI cost interfaces to return an InstructionCost.

See this patch for the introduction of the type: https://reviews.llvm.org/D91174
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2020-November/146408.html

Diff Detail

Event Timeline

sdesmalen created this revision.Apr 15 2021, 7:22 AM
sdesmalen requested review of this revision.Apr 15 2021, 7:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2021, 7:22 AM
c-rhodes added inline comments.Apr 15 2021, 8:21 AM
llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
390

Does there need to be a check the cost is valid before calling getValue?

Assuming @c-rhodes is satisfied, this change looks good to me.

llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
390

Code that handles the invalid case would be a functional change. This follows the philosophy of "the code previously assumed all costs are valid, so we will assume it's valid now and handle the crashes in future functional changes patches if we see them"

sdesmalen marked 2 inline comments as done.Apr 21 2021, 7:13 AM
sdesmalen added inline comments.
llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
390

@c-rhodes seems I wrote this comment but forgot to publish it. The assert in the dereference would fail if the cost is Invalid. We can assume the cost of an instruction in a basic-block is valid, because otherwise it would suggest the instruction cannot be code-generated. This would mean that either the cost-model is broken (it gives an invalid cost for something that _can_ be code-generated), or it means that the IR contains instructions that shouldn't have been created in the first place. As Chris says, changing the code to solve such an issue means making a functional change, and we can just work on the assumption that the cost was valid before this change.

c-rhodes accepted this revision.Apr 21 2021, 7:22 AM
c-rhodes added inline comments.
llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
390

@ctetreau @sdesmalen thanks for clarifying

This revision is now accepted and ready to land.Apr 21 2021, 7:22 AM
This revision was automatically updated to reflect the committed changes.
sdesmalen marked an inline comment as done.