This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen/Analysis] Intrinsic llvm.assume should not block tail call optimization
ClosedPublic

Authored by Carrot on Aug 12 2019, 10:50 AM.

Details

Summary

In function Analysis.cpp:isInTailCallPosition, instructions between call and ret are checked to see if they block tail call optimization. If an instruction is an intrinsic call, only llvm.lifetime_end is allowed and other intrinsic functions block tail call. When compiling tcmalloc, we found llvm.assume between a hot function call and ret, it blocks the optimization. But llvm.assume doesn't generate instructions, it should not block tail call.

Diff Detail

Repository
rL LLVM

Event Timeline

Carrot created this revision.Aug 12 2019, 10:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2019, 10:50 AM
xbolva00 added inline comments.
lib/CodeGen/Analysis.cpp
539 ↗(On Diff #214663)

Update comment

xbolva00 accepted this revision.Aug 12 2019, 10:55 AM

Makes sense

This revision is now accepted and ready to land.Aug 12 2019, 10:55 AM
Carrot updated this revision to Diff 214729.Aug 12 2019, 3:50 PM
Carrot marked an inline comment as done.

Will commit this version.

I'm pretty sure it will not fix the issue. A possible test case would look like:

define i8* @foo() {
  %1 = tail call i8* @bar()
  %2 = icmp eq i8* %1, null
  tail call void @llvm.assume(i1 %2)
  ret i8* null
}

Yes! There is a new PR and I just realized how big issue we have here (we may call functions which are never called in source code) :[

We need to remove all llvm.assumes in CGP.

(That issue needs a separate patch anyway).

Please go ahead with this patch.

This revision was automatically updated to reflect the committed changes.