This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Don't error on calls to null or undef
ClosedPublic

Authored by arsenm on Sep 7 2018, 8:28 AM.

Details

Summary

Calls to constants should probably be generally handled.

Diff Detail

Event Timeline

arsenm created this revision.Sep 7 2018, 8:28 AM

What's the point of hiding an error? We should rather produce a normal error message.

There is no error to hide. This is perfectly valid IR

There is no error to hide. This is perfectly valid IR

Could you elaborate how did we end up with a call to undef?

HCC had a bug recently that was producing calls to under. I assume a call to null would appear for a pure virtual call. They are undefined to execute, but they could appear in dead code that is never reached so it’s not an error to have them exist

HCC had a bug recently that was producing calls to under. I assume a call to null would appear for a pure virtual call. They are undefined to execute, but they could appear in dead code that is never reached so it’s not an error to have them exist

A standard reaction to pure virtual call is a runtime error message and abort. We cannot produce an error message from kernel but we can abort. I would suggest to lower it to s_trap.

arsenm added a comment.Sep 9 2018, 6:42 PM

HCC had a bug recently that was producing calls to under. I assume a call to null would appear for a pure virtual call. They are undefined to execute, but they could appear in dead code that is never reached so it’s not an error to have them exist

A standard reaction to pure virtual call is a runtime error message and abort. We cannot produce an error message from kernel but we can abort. I would suggest to lower it to s_trap.

I don't think this is how that's implemented. Other targets generate a literal call to null in this case. This is an edge case since typically undef/null calls are turned into unreachable in simplifycfg, which there is a flag to generate a trap on separately.

HCC had a bug recently that was producing calls to under. I assume a call to null would appear for a pure virtual call. They are undefined to execute, but they could appear in dead code that is never reached so it’s not an error to have them exist

A standard reaction to pure virtual call is a runtime error message and abort. We cannot produce an error message from kernel but we can abort. I would suggest to lower it to s_trap.

I don't think this is how that's implemented. Other targets generate a literal call to null in this case. This is an edge case since typically undef/null calls are turned into unreachable in simplifycfg, which there is a flag to generate a trap on separately.

That is actually very inconvenient to debug kernels which simply hang or misbehave, even if that is an UB. I still suggest our action of preference on unreachable code is to trap. Whenever we can or cannot do it consistently for all unreachable does not seem to matter, we need to start somewhere.

Considering emitting traps requires fixing traps first, otherwise a program that should work will incorrectly trap

Considering emitting traps requires fixing traps first, otherwise a program that should work will incorrectly trap

Do you agree that is how we have to handle it in principle? If that requres further fixes I do not object a todo comment here.

Considering emitting traps requires fixing traps first, otherwise a program that should work will incorrectly trap

Do you agree that is how we have to handle it in principle? If that requres further fixes I do not object a todo comment here.

I think this purpose would be better served by some sort of sanitizer pass. These would typically be deleted, and it's an anomaly these would reach codegen to bother trapping on. Something else should have inserted a trap for useful debugging purposes

rampitec accepted this revision.Oct 19 2019, 12:18 AM

I think I've seen calls which should be undef recently, but should stay in a dead code. This is the way our library works, and recently the same behavior seems to appear normal with hcc. It is still a fuzzy logic, but that is way we are handling differences between targets, so let it be.

I would still want to emit a call to an error reporting function though. Although I understand that is difficult to emit a good error from a GPU RT.

This revision is now accepted and ready to land.Oct 19 2019, 12:18 AM
arsenm closed this revision.Oct 20 2019, 12:43 AM

r375356