Skip to content

[SandboxIR] Implement UndefValue #107628

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

Merged
merged 2 commits into from
Sep 9, 2024
Merged

[SandboxIR] Implement UndefValue #107628

merged 2 commits into from
Sep 9, 2024

Conversation

vporpo
Copy link
Contributor

@vporpo vporpo commented Sep 6, 2024

This patch implements sandboxir::UndefValue mirroring llvm::UndefValue.

This patch implements sandboxir::UndefValue mirroring llvm::UndefValue.
/// For isa/dyn_cast.
static bool classof(const sandboxir::Value *From) {
return From->getSubclassID() == ClassID::UndefValue ||
From->getSubclassID() == ClassID::PoisonValue;
Copy link

@tschuett tschuett Sep 6, 2024

Choose a reason for hiding this comment

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

isa<PoisonValue>(Undef) is true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm did you mean return From->getSubclassID() == ClassID::UndefValue || isa<PoisonValue(From) ?
I would not prefer this because because it hides the fact that PoisonValue corresponds to just a single ClassID::PoisonValue.

Hmm or did you mean checking the llvm-side with something like isa<PoisonValue>(From->Val) ?

The reason why I don't like this is that it looks like it is slightly slower: Because you need to get From->Val and then run classof() which does the comparison ID == UndefValue || ID == PoisonValue.

Copy link

Choose a reason for hiding this comment

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

You modelled it correctly. Poison inherits from Undef, but an undef value/instance should not be poison.

Copy link

Choose a reason for hiding this comment

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

 static bool classof(const sandboxir::Value *From) {
    return From->getSubclassID() == ClassID::UndefValue;
}

should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, isa<> works because it takes care of upcasting. But classof() would be wrong, it should return true if From is a PoisonValue.

Copy link

Choose a reason for hiding this comment

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

I believe the current classof UndefValue is wrong. It should only test for ClassId::UndefValue.

isa<PoisonValue>(Undef)

should/must be false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

classof() should return true when From is either the current class type (that is UndefValue) or its sub-classes (that is PoisonValue). This is implemented the same way as in llvm/IR/Constants.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isa(Undef) should/must be false.

We are already testing that: EXPECT_FALSE(isa<sandboxir::PoisonValue>(Val: Undef)); // Undef is not Poison

Copy link
Member

Choose a reason for hiding this comment

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

LGTM,

isa<PoisonValue>(Undef_val) is false

@@ -642,6 +642,7 @@ define void @foo() {
// Check classof() and creation.
auto *Poison = cast<sandboxir::PoisonValue>(I0->getOperand(0));
EXPECT_EQ(Poison->getType(), Int32Ty);
EXPECT_TRUE(isa<sandboxir::UndefValue>(Poison)); // Poison is Undef
Copy link

Choose a reason for hiding this comment

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

same problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm what do yo mean? This just checks that a Poison is also an Undef.

Copy link

Choose a reason for hiding this comment

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

This is correct.

Copy link
Member

Choose a reason for hiding this comment

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

LGTM, Poison value is an undef.

@tschuett
Copy link

tschuett commented Sep 6, 2024

Surprise, I misread the LLVM documentation.

@tschuett
Copy link

tschuett commented Sep 6, 2024

Please ignore me:

static bool classof(const Value *V) {

/// For isa/dyn_cast.
static bool classof(const sandboxir::Value *From) {
return From->getSubclassID() == ClassID::UndefValue ||
From->getSubclassID() == ClassID::PoisonValue;
Copy link
Member

Choose a reason for hiding this comment

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

LGTM,

isa<PoisonValue>(Undef_val) is false

@@ -642,6 +642,7 @@ define void @foo() {
// Check classof() and creation.
auto *Poison = cast<sandboxir::PoisonValue>(I0->getOperand(0));
EXPECT_EQ(Poison->getType(), Int32Ty);
EXPECT_TRUE(isa<sandboxir::UndefValue>(Poison)); // Poison is Undef
Copy link
Member

Choose a reason for hiding this comment

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

LGTM, Poison value is an undef.

@vporpo vporpo merged commit ae02211 into llvm:main Sep 9, 2024
8 checks passed
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.

3 participants