Skip to content

Conversation

@danilaml
Copy link
Collaborator

Helps avoid the crash in verifier when it tries to print the error. none token might be produced by llvm-reduce, since it's a default value, so by extension this also fixes llvm-reduce crash, allowing it to just discard invalid IR.

We might special-case tokens in ReduceArguments and to use some other value, other than getDefaultValue (or change the getDefaultValue to use something other than getNullValue for token), but it still wouldn't fix the fact that verifier would crash trying to print an error message if it ever encounters such relocation.
I wasn't able to come up with any potential issues with handling none token as if it was undef, but it doesn't mean that there isn't any =)

Helps avoid the crash in verifier when it tries to print the error. `none` token might be produced by llvm-reduce, since it's a default value, so by extension this also fixes llvm-reduce crash, allowing it to just discard invalid IR.
@llvmbot
Copy link
Member

llvmbot commented Nov 16, 2023

@llvm/pr-subscribers-llvm-ir

Author: Danila Malyutin (danilaml)

Changes

Helps avoid the crash in verifier when it tries to print the error. none token might be produced by llvm-reduce, since it's a default value, so by extension this also fixes llvm-reduce crash, allowing it to just discard invalid IR.

We might special-case tokens in ReduceArguments and to use some other value, other than getDefaultValue (or change the getDefaultValue to use something other than getNullValue for token), but it still wouldn't fix the fact that verifier would crash trying to print an error message if it ever encounters such relocation.
I wasn't able to come up with any potential issues with handling none token as if it was undef, but it doesn't mean that there isn't any =)


Full diff: https://github.com/llvm/llvm-project/pull/72552.diff

2 Files Affected:

  • (modified) llvm/lib/IR/IntrinsicInst.cpp (+5)
  • (added) llvm/test/Verifier/gc_none_token.ll (+18)
diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp index a24ca8d100527d5..77c3bbbb8baecf5 100644 --- a/llvm/lib/IR/IntrinsicInst.cpp +++ b/llvm/lib/IR/IntrinsicInst.cpp @@ -870,6 +870,11 @@ const Value *GCProjectionInst::getStatepoint() const { if (isa<UndefValue>(Token)) return Token; + // Treat none token as if it was undef here + if (isa<ConstantTokenNone>(Token)) { + return UndefValue::get(Token->getType()); + } + // This takes care both of relocates for call statepoints and relocates // on normal path of invoke statepoint. if (!isa<LandingPadInst>(Token)) diff --git a/llvm/test/Verifier/gc_none_token.ll b/llvm/test/Verifier/gc_none_token.ll new file mode 100644 index 000000000000000..3847f625c4869f8 --- /dev/null +++ b/llvm/test/Verifier/gc_none_token.ll @@ -0,0 +1,18 @@ +; RUN: not opt -passes=verify -S %s 2>&1 | FileCheck %s +; Check that verifier doesn't crash on relocate with none token + +target triple = "x86_64-unknown-linux-gnu" + +define i32 @check_verify_none_token() gc "statepoint-example" { + +entry: + ret i32 0 + +unreach: + ; CHECK: gc relocate is incorrectly tied to the statepoint + ; CHECK: (undef, undef) + %token_call = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token none, i32 0, i32 0) + ret i32 1 +} + +declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32) 
Co-authored-by: arpilipe <apilipenko@azul.com>
@danilaml danilaml merged commit 44af592 into llvm:main Nov 17, 2023
@danilaml danilaml deleted the none-token-print branch November 17, 2023 14:32
@nunoplopes
Copy link
Member

Can you use poison here?
We are trying to get rid of undef, so if this can use poison today, it would help the effort.
Thank you!

@danilaml
Copy link
Collaborator Author

danilaml commented Nov 18, 2023

@nunoplopes possibly. Not sure what semantics of this would be though. And this would need to be adapted to poison as well (otherwise there is no point): d693fd2

@nunoplopes
Copy link
Member

@nunoplopes possibly. Not sure what semantics of this would be though. And this would need to be adapted to poison as well (otherwise there is no point): d693fd2

Right. It seems all of those could be converted to poison. It's being used just as a placeholder, so anything works.

sr-tream pushed a commit to sr-tream/llvm-project that referenced this pull request Nov 20, 2023
…lvm#72552) Helps avoid the crash in verifier when it tries to print the error. `none` token might be produced by llvm-reduce, since it's a default value, so by extension this also fixes llvm-reduce crash, allowing it to just discard invalid IR. --------- Co-authored-by: arpilipe <apilipenko@azul.com>
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
…lvm#72552) Helps avoid the crash in verifier when it tries to print the error. `none` token might be produced by llvm-reduce, since it's a default value, so by extension this also fixes llvm-reduce crash, allowing it to just discard invalid IR. --------- Co-authored-by: arpilipe <apilipenko@azul.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment