Skip to content

[GlobalISel] Volatile load duplication - isObviouslySafeToFold is too eager #41377

@llvmbot

Description

@llvmbot
Bugzilla Link 42032
Version trunk
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @aemerson,@dsandersllvm,@qcolombet

Extended Description

isObviouslySafeToFold reports that any neighbouring instructions can "obviously" be folded.

However, globalisel folds without ensuring deletion (as their values may still be live), and so volatile operations can be duplicated erroneously.
One possible workaround:

bool InstructionSelector::isObviouslySafeToFold(MachineInstr &MI,
MachineInstr &IntoMI) const {
// Volatile accesses require special handling:
if (MI.mayLoadOrStore()) {
for (auto mem : MI.memoperands()) {
if (mem->isVolatile())
return false;
}
}
// Immediate neighbours are already folded.
if (MI.getParent() == IntoMI.getParent() &&
std::next(MI.getIterator()) == IntoMI.getIterator())
return !MI.mayLoadOrStore() && !MI.hasUnmodeledSideEffects() &&
empty(MI.implicit_operands());
}

But then, maybe it's time to start discussing improving this whole part of the pattern matcher? Given that at the moment only neighbouring ld/st are considered at all (and once fixed, not if volatile)...

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions