This is an archive of the discontinued LLVM Phabricator instance.

[FuncSpec] Add Freeze and CallBase to the InstCostVisitor.
ClosedPublic

Authored by labrinea on Jun 15 2023, 8:24 AM.

Details

Summary

Allows constant folding of such instructions when estimating user bonus.

Diff Detail

Event Timeline

labrinea created this revision.Jun 15 2023, 8:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2023, 8:24 AM
labrinea requested review of this revision.Jun 15 2023, 8:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2023, 8:24 AM

This is useful for SPEC2017:548.exchange2_r.

labrinea added inline comments.Jun 15 2023, 8:50 AM
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
237

This could perhaps be I.getNumOperands() - 1 but I see no harm as is in case NumOperands == 1 (call with no parameters, operands[0] is the calledOperand). Thinking more about it I believe that's an impossible scenario since we got here (visitCallBase) becase the call must have at least one parameter, so in total at least two operands. Unless the use which brought us here is the calledOperand operand itself. Hmm, don't know. Anyhow too much thinking for such a minor detail. Ignore me.

ChuanqiXu accepted this revision.Jun 17 2023, 12:13 AM

LGTM with comments.

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
241–243

nit:

llvm/unittests/Transforms/IPO/FunctionSpecializationTest.cpp
239–245

It will be better to test the invalid case. e.g., the freeze inst may be position or undef. And the call inst may not be constant. We can test that everything is still fine.

This revision is now accepted and ready to land.Jun 17 2023, 12:13 AM
This revision was landed with ongoing or failed builds.Jun 19 2023, 2:58 AM
This revision was automatically updated to reflect the committed changes.