-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ADT] Fix specialization of ValueIsPresent for PointerUnion #121847
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
Changes from all commits
107a35d
f833dff
13a9098
8abd5cd
294c617
62157bf
0546ba3
f0140f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,10 +134,10 @@ const TargetRegisterClass *RegisterBankInfo::constrainGenericRegister( | |
|
||
// If the register already has a class, fallback to MRI::constrainRegClass. | ||
auto &RegClassOrBank = MRI.getRegClassOrRegBank(Reg); | ||
if (isa<const TargetRegisterClass *>(RegClassOrBank)) | ||
if (isa_and_present<const TargetRegisterClass *>(RegClassOrBank)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think either of these 2 instances should ever encounter a register without a set class or bank, this is papering over a different bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Input gMIR to instruction selector shouldn't contain registers without class/bank.
This is what
I don't know if this should be considered a bug. If it should, I can try to address it separately (probably in #121270). (Unrelated to this PR). Note that the type of the temporary register is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As I mentioned in the other PR this is broken. In no context should an incomplete virtual register be used by an instruction There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears there is another context when class/bank may not be set: 7e1f66d There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After regbankselect / in the selection pass, there must be a class or bank set. The null/null case is only valid before that, when a generic vreg must have a type |
||
return MRI.constrainRegClass(Reg, &RC); | ||
|
||
const RegisterBank *RB = cast<const RegisterBank *>(RegClassOrBank); | ||
const auto *RB = dyn_cast_if_present<const RegisterBank *>(RegClassOrBank); | ||
// Otherwise, all we can do is ensure the bank covers the class, and set it. | ||
if (RB && !RB->covers(RC)) | ||
return nullptr; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,11 @@ TEST_F(PointerUnionTest, NewCastInfra) { | |
EXPECT_FALSE(isa<float *>(d4null)); | ||
EXPECT_FALSE(isa<long long *>(d4null)); | ||
|
||
EXPECT_FALSE(isa_and_present<int *>(i4null)); | ||
EXPECT_FALSE(isa_and_present<float *>(f4null)); | ||
EXPECT_FALSE(isa_and_present<long long *>(l4null)); | ||
EXPECT_FALSE(isa_and_present<double *>(d4null)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, only the first |
||
|
||
// test cast<> | ||
EXPECT_EQ(cast<float *>(a), &f); | ||
EXPECT_EQ(cast<int *>(b), &i); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going down this route, it would probably make sense to also change the enable_if to check std::is_convertible<T, bool> instead?
I think you could also drop the separate std::optional specialization because it also has operator bool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will make much more sense, will try.
They are not quite the same, the specialization for
std::optional
derefernces the argument ofunwrapValue()
.This can probably be guarded by
constexpr if
, but personally I find the separate specialization clearer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears
is_convertible
only handles implicit conversions, i.e. it returns false for types withexplicit operator bool()
. I usedis_constructible
with swapped arguments instead.