This is an archive of the discontinued LLVM Phabricator instance.

[mlir][llvm] Add inbounds attriubte to the gep op.
ClosedPublic

Authored by gysit on Dec 12 2022, 1:54 AM.

Details

Summary

The revision adds an inbounds attribute to the LLVM dialect
GEP operation. It extends the builders and the import and export
to support the optional inbounds attribute.

As all builders set inbounds to false by default, existing lowerings
from higher-level dialects to LLVM dialect are not affected by the
change. Canonicalization/folding remains untouched since it currently
does not implement any simplifications in case of undefined behavior
(the handling of undefined behavior is deferred to LLVM).

Diff Detail

Event Timeline

gysit created this revision.Dec 12 2022, 1:54 AM
Herald added a project: Restricted Project. · View Herald Transcript
gysit requested review of this revision.Dec 12 2022, 1:54 AM

Thanks for doing what should have been done years ago! :)

I've been thinking about "magic bools" in builders (b.create<GEPOp>(..., /*inbounds=*/true)). What's your opinion on using named zero-size structs instead (b.create<GEPOp>(..., GEPOp::InBounds()))? Not asking to implement, just for an opinion.

ftynse accepted this revision.Dec 13 2022, 10:04 PM
This revision is now accepted and ready to land.Dec 13 2022, 10:04 PM
gysit added a comment.Dec 14 2022, 1:25 AM

I've been thinking about "magic bools" in builders (b.create<GEPOp>(..., /*inbounds=*/true)). What's your opinion on using named zero-size structs instead (b.create<GEPOp>(..., GEPOp::InBounds()))? Not asking to implement, just for an opinion.

I like the idea. Having an explicit GEPOp::InBounds() is clearly more readable and trustworthy than the c-style comments /*inbounds=*/true. Especially, since I tend to look at other builder uses due to the missing autocompletion (I know I should look at the tablegen file :)).

How would you handle default values with this design? Would you provide multiple build methods instead of having a default value or is there another trick?

Multiple overloads, or wrapping a bool into a struct with the default constructor putting a true and a regular taking the value that is set to false in the default argument initialization.

gysit added a comment.Dec 14 2022, 1:42 AM

Multiple overloads, or wrapping a bool into a struct with the default constructor putting a true and a regular taking the value that is set to false in the default argument initialization.

Yeah, I think wrapping a bool may be nice!

This revision was automatically updated to reflect the committed changes.