This is an archive of the discontinued LLVM Phabricator instance.

[mlir][LLVMIR] Do not cache llvm::Constant into instMap
ClosedPublic

Authored by myhsu on Apr 25 2022, 9:59 AM.

Details

Summary

Constants in MLIR are not globally unique, unlike in LLVM IR. Therefore, reusing previously-translated constants might create operations that are not dominated by the constant (because the previously-translated ones can be placed anywhere)

This indeed misses some opportunities where we actually can reuse a previously-translated constant, but verbosity is not our first priority here.

(Note that the test case attached looks really similar to that in D124402, but the indices in ConstantExpr-GEP are different: in this patch all of them are zeros. Without this patch, the llvm.getelementptr translated from the second ConstantExpr-GEP will try to use llvm.constant(0: i32)-s that are below itself, because we're reusing the cached ConstantInt-type zero value translated earlier)

Diff Detail

Event Timeline

myhsu created this revision.Apr 25 2022, 9:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 9:59 AM
myhsu requested review of this revision.Apr 25 2022, 9:59 AM
myhsu edited the summary of this revision. (Show Details)Apr 25 2022, 10:02 AM
ftynse edited the summary of this revision. (Show Details)Apr 26 2022, 1:16 AM

I edited the description a bit. Please also note that phabricator-style markup (e.g., using // for italic) looks weird in git commit messages (e.g., C-style comment).

even another llvm.func!

Isn't the cache cleared on entering a new function? The error is only manifest for globals.

mlir/test/Target/LLVMIR/Import/incorrect-constant-caching.ll
5–24

Could you please describe in text what was happening before this patch? This will help to differentiate regressions from other kinds of test breakages in the future.

myhsu updated this revision to Diff 425375.Apr 26 2022, 5:57 PM
myhsu marked an inline comment as done.
myhsu edited the summary of this revision. (Show Details)

add bug descriptions into the test file.

myhsu added a comment.Apr 26 2022, 5:58 PM

I edited the description a bit. Please also note that phabricator-style markup (e.g., using // for italic) looks weird in git commit messages (e.g., C-style comment).

even another llvm.func!

Isn't the cache cleared on entering a new function? The error is only manifest for globals.

Yes you're right, I'd removed this from description / commit message.

ftynse accepted this revision.Apr 27 2022, 3:49 AM
This revision is now accepted and ready to land.Apr 27 2022, 3:49 AM
This revision was automatically updated to reflect the committed changes.