This is an archive of the discontinued LLVM Phabricator instance.

Mark type test intrinsics as speculatable to fix inline cost
ClosedPublic

Authored by tejohnson on Apr 23 2021, 9:39 AM.

Details

Summary

There is already code in InlineCost.cpp to identify and ignore ephemeral
values (llvm.assume intrinsics and other side-effect free instructions
only feeding the assumes). However, because llvm.type.test intrinsics
were not marked speculatable, they and any instructions specifically
feeding the type test (typically a bitcast) were being counted towards
the instruction cost when inlining. This was causing profile matching
issues in some cases when enabling -fwhole-program-vtables for whole
program devirtualization.

According to the language reference, the speculatable attribute means:
"the function does not have any effects besides calculating its result
and does not have undefined behavior". I see no reason why type tests
cannot be marked with this attribute.

There are 2 test changes:

llvm/test/Transforms/Inline/ephemeral.ll: I added a type test intrinsic
here to verify the fix. Also, I found the test was not actually testing
what it originally intended. Many of the existing instructions were
optimized away by -Oz, and the cost of inlining was negative due to the
benefit of removing the call. So I changed the test to simply invoke the
inline pass and check the number of instructions computed by InlineCost.
I also fixed an instruction that was not actually used anywhere.

llvm/test/Transforms/SimplifyCFG/no-md-sink.ll needed to be made more
robust to code changes that reordered the metadata.

Diff Detail

Event Timeline

tejohnson created this revision.Apr 23 2021, 9:39 AM
tejohnson requested review of this revision.Apr 23 2021, 9:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2021, 9:39 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
This revision is now accepted and ready to land.Apr 23 2021, 10:01 AM
This revision was landed with ongoing or failed builds.Apr 23 2021, 10:02 AM
This revision was automatically updated to reflect the committed changes.

I have an auto bisecting cron job that has twice identified this change as the source of a regression when building release (no asserts). Is the following expected or can we get a quick fix?

FAIL: LLVM :: Transforms/Inline/ephemeral.ll (57376 of 76078)
******************** TEST 'LLVM :: Transforms/Inline/ephemeral.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /tmp/_update_lc/r/bin/opt -S -inline /home/dave/ro_s/lp/llvm/test/Transforms/Inline/ephemeral.ll -debug-only=inline-cost 2>&1 | /tmp/_update_lc/r/bin/FileCheck /home/dave/ro_s/lp/llvm/test/Transforms/Inline/ephemeral.ll
--
Exit Code: 1

Command Output (stderr):
--
/home/dave/ro_s/lp/llvm/test/Transforms/Inline/ephemeral.ll:4:10: error: CHECK: expected string not found in input
; CHECK: NumInstructions: 2
         ^
<stdin>:1:1: note: scanning from here
opt: Unknown command line argument '-debug-only=inline-cost'. Try: '/tmp/_update_lc/r/bin/opt --help'
^
<stdin>:2:33: note: possible intended match here
opt: Did you mean '--debug-pass=inline-cost'?
                                ^

Input file: <stdin>
Check file: /home/dave/ro_s/lp/llvm/test/Transforms/Inline/ephemeral.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: opt: Unknown command line argument '-debug-only=inline-cost'. Try: '/tmp/_update_lc/r/bin/opt --help'
check:4'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: opt: Did you mean '--debug-pass=inline-cost'?
check:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:4'1                                     ?              possible intended match
>>>>>>

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
********************
Failed Tests (1):
  LLVM :: Transforms/Inline/ephemeral.ll

I have an auto bisecting cron job that has twice identified this change as the source of a regression when building release (no asserts). Is the following expected or can we get a quick fix?

Ah, this test now uses a debug flag so needs to require asserts. Should be fixed in 38959c4624345d7e6b7d726d87c79c083298b189.

FAIL: LLVM :: Transforms/Inline/ephemeral.ll (57376 of 76078)
******************** TEST 'LLVM :: Transforms/Inline/ephemeral.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /tmp/_update_lc/r/bin/opt -S -inline /home/dave/ro_s/lp/llvm/test/Transforms/Inline/ephemeral.ll -debug-only=inline-cost 2>&1 | /tmp/_update_lc/r/bin/FileCheck /home/dave/ro_s/lp/llvm/test/Transforms/Inline/ephemeral.ll
--
Exit Code: 1

Command Output (stderr):
--
/home/dave/ro_s/lp/llvm/test/Transforms/Inline/ephemeral.ll:4:10: error: CHECK: expected string not found in input
; CHECK: NumInstructions: 2
         ^
<stdin>:1:1: note: scanning from here
opt: Unknown command line argument '-debug-only=inline-cost'. Try: '/tmp/_update_lc/r/bin/opt --help'
^
<stdin>:2:33: note: possible intended match here
opt: Did you mean '--debug-pass=inline-cost'?
                                ^

Input file: <stdin>
Check file: /home/dave/ro_s/lp/llvm/test/Transforms/Inline/ephemeral.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: opt: Unknown command line argument '-debug-only=inline-cost'. Try: '/tmp/_update_lc/r/bin/opt --help'
check:4'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: opt: Did you mean '--debug-pass=inline-cost'?
check:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:4'1                                     ?              possible intended match
>>>>>>

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
********************
Failed Tests (1):
  LLVM :: Transforms/Inline/ephemeral.ll