This is an archive of the discontinued LLVM Phabricator instance.

[mlir][LLVMIR] Do not cache Instruction generated on-the-fly
ClosedPublic

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

Details

Summary

We want to avoid caching llvm::Instruction generated by llvm::ConstantExpr::getAsInstruction into instMap. Because if we remove it right away, it's possible that when getAsInstruction is called again, it will create a new instruction that has the same address with the one we just deleted. Inducing a conflicting index in instMap and triggers an assertion in processInstruction.

Note that this patch depends on D124399 simply because it's easier to trigger this bug by putting ConstantExpr inside a ConstantAggregate, which is also how the test case was written.

Diff Detail

Event Timeline

myhsu created this revision.Apr 25 2022, 9:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 9:49 AM
myhsu requested review of this revision.Apr 25 2022, 9:49 AM
rriddle added inline comments.Apr 25 2022, 9:56 AM
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
502

Can't we just remove the mapping of i inside of instMap? Wouldn't that make it safe to delete here?

myhsu updated this revision to Diff 425115.Apr 25 2022, 9:35 PM
myhsu marked an inline comment as done.
myhsu retitled this revision from [mlir][LLVMIR] Defer the removal of Instruciton generated on-the-fly to [mlir][LLVMIR] Do not cache Instruction generated on-the-fly.
myhsu edited the summary of this revision. (Show Details)

Taking @rriddle 's advice and simplify the patch

ftynse accepted this revision.Apr 26 2022, 1:23 AM

Nice catch, thanks!

This revision is now accepted and ready to land.Apr 26 2022, 1:23 AM