[PATCH] D80661: [CodeGen] Enable tail call position check for speculatable functions

Victor Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 27 14:10:16 PDT 2020


NeHuang created this revision.
NeHuang added reviewers: nemanjai, stefanp, lei, bogner, jdoerfert, dwightguth, hfinkel, power-llvm-team.
NeHuang added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.

In the function "Analysis.cpp:isInTailCallPosition",  it only checks whether a call is in a tail call position if the call has side effects, access memory or it is not safe to speculative execute. Therefore, a speculatable function will not go through tail call position check and improperly tail called when it is not in a tail-call position.  An example as below:

IR reproducer

  define dso_local void @caller(double* nocapture %res, double %a) local_unnamed_addr #0 {
  entry:
    %call = tail call double @callee(double %a) #2
    store double %call, double* %res, align 8
    ret void
  }
  define double @callee(double) local_unnamed_addr #1 {
    ret double 4.5
  }
  attributes #0 = { nounwind }
  attributes #1 = { readnone speculatable }
  attributes #2 = { nounwind noinline }

produces a tail call in the caller without storing the result, which can be seen in the initial SDAG below

  llc < reproducer.ll -debug-only=isel -mtriple=x86_64
  === caller
  Initial selection DAG: %bb.0 'caller:entry'
  SelectionDAG has 12 nodes:
    t0: ch = EntryToken
    t2: i64,ch = CopyFromReg t0, Register:i64 %0
    t5: i64 = GlobalAddress<double (double)* @callee> 0
      t4: f64,ch = CopyFromReg t0, Register:f64 %1
    t7: ch,glue = CopyToReg t0, Register:f64 $xmm0, t4
    t11: ch,glue = X86ISD::TC_RETURN t7, TargetGlobalAddress:i64<double (double)* @callee> 0, Constant:i32<0>, Register:f64 $xmm0, RegisterMask:Untyped, t7:1

This patch enables tail call position check for speculatable functions if their results used by a non-return instruction.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80661

Files:
  llvm/lib/CodeGen/Analysis.cpp
  llvm/test/CodeGen/PowerPC/tailcall-speculatable-callee.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80661.266636.patch
Type: text/x-patch
Size: 3893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200527/5fdc944f/attachment-0001.bin>


More information about the llvm-commits mailing list