This is an archive of the discontinued LLVM Phabricator instance.

X86: Don't reset the stack after calls that don't return (PR27117)
ClosedPublic

Authored by hans on May 18 2016, 6:04 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

hans updated this revision to Diff 57719.May 18 2016, 6:04 PM
hans retitled this revision from to X86: Don't reset the stack after calls that don't return (PR27117).
hans updated this object.
hans added reviewers: rnk, mkuper.
hans added a subscriber: llvm-commits.
rnk added inline comments.May 19 2016, 10:30 AM
include/llvm/Target/TargetLowering.h
2525 ↗(On Diff #57719)

Call can be an invoke, in which case it terminates, in which case this may call isa<> on an end iterator, which is bad. I think the easy way to avoid this case is check for !Call.isInvoke() && ....

lib/Target/X86/X86ISelLowering.cpp
3384 ↗(On Diff #57719)

We should kill that TargetOption eventually...

majnemer added inline comments.
include/llvm/Target/TargetLowering.h
2525 ↗(On Diff #57719)

Instead of isa<UnreachableInst>(++Call.getInstruction()->getIterator()) you could do isa<UnreachableInst>(Call.getInstruction()->getNextNode()) which is a little shorter (and simpler IMO).

rnk added inline comments.May 19 2016, 10:56 AM
include/llvm/Target/TargetLowering.h
2525 ↗(On Diff #57719)

I think you have to null check getNextNode, though.

hans added inline comments.May 19 2016, 12:53 PM
include/llvm/Target/TargetLowering.h
2525 ↗(On Diff #57719)

Oh right, I forgot invokes are terminators. Adding the !Call.isInvoke() check.

2525 ↗(On Diff #57719)

Thanks! I'll do that.

2525 ↗(On Diff #57719)

But not if we know the instruction isn't last in the BB right?

hans updated this revision to Diff 57841.May 19 2016, 12:53 PM

Addressing comments.

rnk accepted this revision.May 19 2016, 1:07 PM
rnk edited edge metadata.

lgtm

This revision is now accepted and ready to land.May 19 2016, 1:07 PM
This revision was automatically updated to reflect the committed changes.
rnk added a comment.Mar 2 2020, 12:43 PM

It looks like we still have this problem, despite many attempts to fix it. rG5b79e603d3b7a29940df6580d6f62b0e9bd339c0 / D66905, for example.

If you enable exceptions, my checks aren't enough. This C++ code for example:

struct MakeCleanup {
  ~MakeCleanup();
};
bool cond();
void foo() {
  MakeCleanup o;
  if (cond())
    throw;
  if (cond())
    throw;
}

I think we should look into removing this x86isellowering code.

Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2020, 12:43 PM