If an instance (InsertionPoint or IP) of Base constant A has only one or few rebased constants depending on it, do NOT rebase. One extra ADD instruction is required to materialize each rebased constant, assuming A and the rebased have the same materialization cost.
Details
- Reviewers
efriedma • zinob javed.absar wmi SjoerdMeijer mehdi_amini dmgreen - Commits
- rG95710337b4df: Revert "Revert "[ConstHoist] Do not rebase single (or few) dependent constant""
rG2c1a09188f12: [ConstHoist] Do not rebase single (or few) dependent constant
rL343053: Revert "Revert "[ConstHoist] Do not rebase single (or few) dependent constant""
rL342994: [ConstHoist] Do not rebase single (or few) dependent constant
Diff Detail
- Repository
- rL LLVM
Event Timeline
This does seem, from the tests I ran, to reduce codesize on average. Especially on Thumb1.
lib/Transforms/Scalar/ConstantHoisting.cpp | ||
---|---|---|
873 ↗ | (On Diff #166012) | Can you change this around so we don't speculatively make the Base? That seems to be the way of doing things in LLVM. |
test/CodeGen/Thumb/consthoist-single-dependent.ll | ||
1 ↗ | (On Diff #166012) | Would these tests make more sense as opt tests? That way they can just test this specific pass, not the entire backend. |
123 ↗ | (On Diff #166012) | Clean up tests please. |
test/CodeGen/Thumb/consthoist-single-dependent.ll | ||
---|---|---|
1 ↗ | (On Diff #166012) | Perhaps as-well-as, not instead-of? If you still want to test this behaviour too. |
Cleaned up test case.
Added opt tests.
Opt tests was put in the same test file to avoid duplication and maintenance burden.
lib/Transforms/Scalar/ConstantHoisting.cpp | ||
---|---|---|
873 ↗ | (On Diff #166012) | Here Base is not the base constant, but an instance (insertion point) of it. A base constant can have multiple insertion points. The existing algorithm first finds the insertion points, then looks for rebased uses dominated by each insertion point. If I understand your comments correctly, it's desirable to not to have Base at the first place so no need to erase it later. But we need the number of rebased uses to determine if we'll rewrite such uses. To get this number we need Base. I can remove the statement: Base->eraseFromParent(); Since Base has no use, it'll be trivially removed by DCE. |
lib/Transforms/Scalar/ConstantHoisting.cpp | ||
---|---|---|
873 ↗ | (On Diff #166012) | (I think) because we are inserting Base at IP, Base->getParent will just be IP->getParent, and if we use that we can move the code to create Base (and the debug message after) to after this check. Unless findMatInsertPt is doing something I don't expect and requiring that Base has been created? Make sure that works, and all the tests are passing. |
test/CodeGen/Thumb/consthoist-single-dependent.ll | ||
14 ↗ | (On Diff #166580) | Can you add the bb these are expected to be in, like in "carla" below. I think thats good at makes the intent a lot clearer. |
Moved collecting dependent rebased and checking size of ToBeRebased prior to emitting bitcast of base constants
Added bb labels to check in the test case.
lib/Transforms/Scalar/ConstantHoisting.cpp | ||
---|---|---|
873 ↗ | (On Diff #166012) | Ah, didn't see this. Thanks. |
LGTM, with one minor Nit.
test/CodeGen/Thumb/consthoist-single-dependent.ll | ||
---|---|---|
60 ↗ | (On Diff #166766) | You can remove this phab reference, or point to the test added there. |