Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LLVM] Fix CodeGenLLVM::LinkParameters #8213

Merged
merged 1 commit into from
Jun 10, 2021
Merged

[LLVM] Fix CodeGenLLVM::LinkParameters #8213

merged 1 commit into from
Jun 10, 2021

Conversation

kparzysz-quic
Copy link
Contributor

  • Generate valid LLVM IR.
  • Set proper alignment on the constant variables.

- Generate valid LLVM IR.
- Set proper alignment on the constant variables.
@ANSHUMAN87
Copy link
Contributor

  • Generate valid LLVM IR.
  • Set proper alignment on the constant variables.

@kparzysz-quic : could you please describe what was the issue? And possibly scenario to reproduce the issue. Thanks!

@kparzysz-quic
Copy link
Contributor Author

The generated LLVM IR was not valid: for example it had bitcasts between pointer and array types.

@ANSHUMAN87
Copy link
Contributor

The generated LLVM IR was not valid: for example it had bitcasts between pointer and array types.

Thanks for your response. Will it be possible for you to share one small snippets which will show LLVM IR before your change where the issue lies, and after your fix the resulting LLVM IR where the issue is resolved. TIA!

@kparzysz-quic
Copy link
Contributor Author

If you use LLVM with assertions enabled, it will simply not allow you to create such a bitcast: attempt to do so will trigger an assertion.

@kparzysz-quic
Copy link
Contributor Author

This is the assertion that I'm getting without this patch:

python3: /w/src/llvm-project/llvm/lib/IR/Type.cpp:689: static llvm::PointerType *llvm::PointerType::get(llvm::Type *, unsigned int): Assertion `isValidElementType(EltTy) && "Invalid type for pointer element!"' failed.

@kparzysz-quic
Copy link
Contributor Author

The above assertion is because the program tried to get a pointer to void in LLVM. There is no such thing, hence the assertion. After you fix that, you hit another problem: the bitcast that was on line 221 was casting i8* %0 to [1 x i8*], which is not a legal cast, and so you get another assertion:

python3: /w/src/llvm-project/llvm/lib/IR/Instructions.cpp:2984: static llvm::CastInst *llvm::CastInst::Create(Instruction::CastOps, llvm::Value *, llvm::Type *, const llvm::Twine &, llvm::Instruction *): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.

@ANSHUMAN87
Copy link
Contributor

Thanks a lot @kparzysz-quic for clarification 👍

Copy link
Contributor

@areusch areusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing this, @kparzysz-quic ! is it possible to add a unit test to demonstrate the incorrect usage?

src/target/llvm/codegen_llvm.cc Show resolved Hide resolved
@kparzysz-quic
Copy link
Contributor Author

The test tests/python/unittest/test_link_params.py fails without this patch. How come it wasn't failing in the CI?

@kparzysz-quic
Copy link
Contributor Author

I think I know what's going on: if you use LLVM that was compiled without assertions, it may not crash at the time of generating the LLVM IR. I guess that the generated LLVM IR ends up working correctly, at least in this case.

I use LLVM with built-in assertions, so for me it crashes. I don't know if there is a reliable way to make the current code fail without using assertions in LLVM.

@areusch
Copy link
Contributor

areusch commented Jun 9, 2021

@kparzysz-quic yeah i think you're right--we get LLVM from APT in the docker container, which i doubt has -DLLVM_ENABLE_ASSERTIONS as the website mentions it's slow. For that reason, I'm hesitant to suggest changing our LLVM install process to build one with assertions as it might significantly impact the CI speed. we could potentially add one version which contains assertions and run codegen unit tests against that. what are your thoughts?

@kparzysz-quic
Copy link
Contributor Author

I've been using the entire clang toolchain built with assertions (the Release+Assertions build) in my daily work and I don't find it too slow. Frankly, I'm not sure if I could tell whether I'm running Release or Release+Assertions without some known references or comparing them side by side. I wouldn't be concerned at all about using such a build for CI. The slowness issue would definitely come up with a Debug build, which AFAIR is unoptimized.

@kparzysz-quic
Copy link
Contributor Author

What else needs to be done for this PR?

@areusch
Copy link
Contributor

areusch commented Jun 10, 2021

ok, just wanted to understand those points. it seems like we should modify our LLVM install to build with assertions on in at least one version in one container. that doesn't have to block this PR, though. could you just clarify your answer to the one question about GEP and we can merge?

@areusch areusch merged commit 4079ffd into apache:main Jun 10, 2021
@areusch
Copy link
Contributor

areusch commented Jun 10, 2021

thanks @kparzysz-quic , the PR is now merged

@kparzysz-quic kparzysz-quic deleted the kparzysz-link-params branch June 10, 2021 19:01
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Jun 17, 2021
- Generate valid LLVM IR.
- Set proper alignment on the constant variables.
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Jun 17, 2021
- Generate valid LLVM IR.
- Set proper alignment on the constant variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants