This is an archive of the discontinued LLVM Phabricator instance.

[mlir][UBToLLVM] Do not arbitrarily restrict input types
ClosedPublic

Authored by zero9178 on Aug 28 2023, 6:06 AM.

Details

Summary

The lowering pattern is currently restricted to integer, float and index types.
This is seemingly arbitrary, as ub.poison works for any input type. The lowering should therefore also work with any type that can be converted using the type converter.

This patch therefore simply removes that condition and adds a test ensuring that this works.

Diff Detail

Event Timeline

zero9178 created this revision.Aug 28 2023, 6:06 AM
Herald added a project: Restricted Project. · View Herald Transcript
zero9178 requested review of this revision.Aug 28 2023, 6:06 AM

My motivation for limiting this pattern was to avoid converting user types as user might have different lowering for poison. But it is purely theoretical, I don't have any specific examples.

zero9178 updated this revision to Diff 553934.Aug 28 2023, 7:51 AM

Restrict pattern to #ub.poison only

My motivation for limiting this pattern was to avoid converting user types as user might have different lowering for poison. But it is purely theoretical, I don't have any specific examples.

I now changed the implementation to only perform the folding if using the default #ub.poison attribute. In this case this pattern should be completely correct as it is fully poisoned. The current lowering would be incorrect for any other attribute.
Any other implementation of a PoisonAttrInterface is not handled by the pattern and almost certainly wants a custom lowering.

If threoretically a user might want a different lowering, they could just not use this pass, or register this pattern as part of their UB lowering.

kuhar accepted this revision.Aug 28 2023, 7:58 AM

My motivation for limiting this pattern was to avoid converting user types as user might have different lowering for poison. But it is purely theoretical, I don't have any specific examples.

I now changed the implementation to only perform the folding if using the default #ub.poison attribute. In this case this pattern should be completely correct as it is fully poisoned. The current lowering would be incorrect for any other attribute.
Any other implementation of a PoisonAttrInterface is not handled by the pattern and almost certainly wants a custom lowering.

If threoretically a user might want a different lowering, they could just not use this pass, or register this pattern as part of their UB lowering.

This makes sense to me. We should probably extend the documentation soon to explain these semantics, similar to https://mlir.llvm.org/docs/Rationale/SideEffectsAndSpeculation/ to avoid future ambiguities here. And I'm sure it will take a while to iron everything out.

mlir/lib/Conversion/UBToLLVM/UBToLLVM.cpp
45–50

ubernit: I'd prefer braces around ifs with multi-line body

This revision is now accepted and ready to land.Aug 28 2023, 7:58 AM
Hardcode84 accepted this revision.Aug 28 2023, 7:59 AM

LGTM (FYI, we have a similar pattern in UBToSPIRV)

This revision was landed with ongoing or failed builds.Aug 28 2023, 8:19 AM
This revision was automatically updated to reflect the committed changes.
zero9178 marked an inline comment as done.