This is an archive of the discontinued LLVM Phabricator instance.

Teach InlineCost about address spaces
ClosedPublic

Authored by bjope on Nov 25 2017, 6:17 AM.

Details

Summary

I basically copied this patch from here: https://reviews.llvm.org/D1251
But I skipped some of the refactoring to make the patch more clean.

The new outer3/inner3 test case in ptr-diff.ll triggers the following assert without this patch:
lib/IR/Constants.cpp:1834: static llvm::Constant *llvm::ConstantExpr::getCompare(unsigned short, llvm::Constant *, llvm::Constant *, bool): Assertion `C1->getType() == C2->getType() && "Op types should be identical!"' failed.

The other new test cases makes sure that there is code coverage for all modifications in InlineCost.cpp (getting different values due to not fetching sizes for address space zero). I only guarantee code coverage for those tests. The tests are not written in a way that they would break if not having the corrections in InlineCost.cpp. I found it quite hard to fine tune the tests into getting different results based on the pointer sizes (except for the test case where we hit an assert if not teaching InlineCost about address spaces).

Diff Detail

Repository
rL LLVM

Event Timeline

bjope created this revision.Nov 25 2017, 6:17 AM
bjope added a reviewer: haicheng.
arsenm accepted this revision.Nov 27 2017, 10:10 AM

LGTM

This revision is now accepted and ready to land.Nov 27 2017, 10:10 AM
arsenm requested changes to this revision.Nov 27 2017, 10:11 AM

Actually the test seems to just cover the ptrtoint case. Need some for the GEP cases as well

This revision now requires changes to proceed.Nov 27 2017, 10:11 AM
bjope updated this revision to Diff 125410.Dec 4 2017, 1:47 PM
bjope edited edge metadata.

Added some more tests.

bjope edited the summary of this revision. (Show Details)Dec 4 2017, 1:50 PM
bjope edited the summary of this revision. (Show Details)
bjope added a comment.Dec 12 2017, 4:48 AM

Actually the test seems to just cover the ptrtoint case. Need some for the GEP cases as well

So, are the new test cases enough?

arsenm accepted this revision.Jan 3 2018, 10:16 AM

LGTM

This revision is now accepted and ready to land.Jan 3 2018, 10:16 AM
This revision was automatically updated to reflect the committed changes.
skatkov added a subscriber: skatkov.EditedJan 9 2018, 9:13 PM

Dear Bjorn, your added test in byvall.ll expose the problem in inliner causing an assert.

Specifically if I excerpt you test in separate file and run:
$ opt -S -inline -instcombine test.ll
I've got a
opt: ../../lib/Analysis/ValueTracking.cpp:1551: void computeKnownBits(const llvm::Value*, llvm::KnownBits&, unsigned int, const {anonymous}::Query&): Assertion `Q.DL.getTypeSizeInBits(V->getType()->getScalarType()) == BitWidth && "V and Known should have same BitWidth"' failed.

The reason of this is that %p is substituted with
%d = alloca %struct.S1, align 8
which is from addrspace(0) and has a different pointer size than %p.

I'm far from thinking that your patch is causing this issue but probably it is long standing issue in inliner. But it causes the crash in our custom pipeline.
I do not want to revert your patch if you can quickly update the test or simply revert the test itself.

A separate bug against inliner can be filed...

Does it make sense to you?

Dear Bjorn, your added test in byvall.ll expose the problem in inliner causing an assert.

Specifically if I excerpt you test in separate file and run:
$ opt -S -inline -instcombine test.ll
I've got a
opt: ../../lib/Analysis/ValueTracking.cpp:1551: void computeKnownBits(const llvm::Value*, llvm::KnownBits&, unsigned int, const {anonymous}::Query&): Assertion `Q.DL.getTypeSizeInBits(V->getType()->getScalarType()) == BitWidth && "V and Known should have same BitWidth"' failed.

The reason of this is that %p is substituted with
%d = alloca %struct.S1, align 8
which is from addrspace(0) and has a different pointer size than %p.

I'm far from thinking that your patch is causing this issue but probably it is long standing issue in inliner. But it causes the crash in our custom pipeline.
I do not want to revert your patch if you can quickly update the test or simply revert the test itself.

A separate bug against inliner can be filed...

Does it make sense to you?

Ok. I'll take a look at it.

Thank you very much!

bjope added a comment.Jan 10 2018, 4:21 AM

Dear Bjorn, your added test in byvall.ll expose the problem in inliner causing an assert.

Specifically if I excerpt you test in separate file and run:
$ opt -S -inline -instcombine test.ll
I've got a
opt: ../../lib/Analysis/ValueTracking.cpp:1551: void computeKnownBits(const llvm::Value*, llvm::KnownBits&, unsigned int, const {anonymous}::Query&): Assertion `Q.DL.getTypeSizeInBits(V->getType()->getScalarType()) == BitWidth && "V and Known should have same BitWidth"' failed.

The reason of this is that %p is substituted with
%d = alloca %struct.S1, align 8
which is from addrspace(0) and has a different pointer size than %p.

I'm far from thinking that your patch is causing this issue but probably it is long standing issue in inliner. But it causes the crash in our custom pipeline.
I do not want to revert your patch if you can quickly update the test or simply revert the test itself.

A separate bug against inliner can be filed...

Does it make sense to you?

Ok. I'll take a look at it.

Here is an attempt to workaround the problem: https://reviews.llvm.org/D41898