[ICP] Handling must tail calls in indirect call promotion
authorHongtao Yu <hoy@fb.com>
Fri, 1 May 2020 19:44:46 +0000 (12:44 -0700)
committerHongtao Yu <hoy@fb.com>
Sun, 3 May 2020 17:42:22 +0000 (10:42 -0700)
commit911e06f5eba66516e87c73d8e76016e549051cd7
treeed5650cbaa7eec3e3fe635882de97f8e20b141f8
parentbec4ab95a4b7ed2a875af8a56189784d37a4ca12
[ICP] Handling must tail calls in indirect call promotion

Per the IR convention, a musttail call must precede a ret with an optional bitcast. This was violated by the indirect call promotion optimization which could result an IR like:

    ; <label>:2192:
      br i1 %2198, label %2199, label %2201, !dbg !226012, !prof !229483

    ; <label>:2199:                                   ; preds = %2192
      musttail call fastcc void @foo(i8* %2195), !dbg !226012
      br label %2202, !dbg !226012

    ; <label>:2201:                                   ; preds = %2192
      musttail call fastcc void %2197(i8* %2195), !dbg !226012
      br label %2202, !dbg !226012

    ; <label>:2202:                                   ; preds = %605, %2201, %2199
      ret void, !dbg !229485

This is being fixed in this change where the return statement goes together with the promoted indirect call. The code generated is like:

    ; <label>:2192:
      br i1 %2198, label %2199, label %2201, !dbg !226012, !prof !229483

    ; <label>:2199:                                   ; preds = %2192
      musttail call fastcc void @foo(i8* %2195), !dbg !226012
      ret void, !dbg !229485

    ; <label>:2201:                                   ; preds = %2192
      musttail call fastcc void %2197(i8* %2195), !dbg !226012
      ret void, !dbg !229485

Differential Revision: https://reviews.llvm.org/D79258
llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
llvm/test/Transforms/PGOProfile/indirect_call_promotion_musttail.ll [new file with mode: 0644]