2018-07-19 16:51:32 +02:00
|
|
|
; REQUIRES: x86-registered-target
|
|
|
|
|
|
|
|
; Test CFI devirtualization through the thin link and backend.
|
|
|
|
|
[LTO] Record whether LTOUnit splitting is enabled in index
Summary:
Records in the module summary index whether the bitcode was compiled
with the option necessary to enable splitting the LTO unit
(e.g. -fsanitize=cfi, -fwhole-program-vtables, or -fsplit-lto-unit).
The information is passed down to the ModuleSummaryIndex builder via a
new module flag "EnableSplitLTOUnit", which is propagated onto a flag
on the summary index.
This is then used during the LTO link to check whether all linked
summaries were built with the same value of this flag. If not, an error
is issued when we detect a situation requiring whole program visibility
of the class hierarchy. This is the case when both of the following
conditions are met:
1) We are performing LowerTypeTests or Whole Program Devirtualization.
2) There are type tests or type checked loads in the code.
Note I have also changed the ThinLTOBitcodeWriter to also gate the
module splitting on the value of this flag.
Reviewers: pcc
Subscribers: ormris, mehdi_amini, Prazek, inglorion, eraman, steven_wu, dexonsmith, arphaman, dang, llvm-commits
Differential Revision: https://reviews.llvm.org/D53890
llvm-svn: 350948
2019-01-11 19:31:57 +01:00
|
|
|
; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s
|
2018-07-19 16:51:32 +02:00
|
|
|
|
|
|
|
; Legacy PM
|
2018-08-14 05:00:16 +02:00
|
|
|
; RUN: llvm-lto2 run %t.o -save-temps -pass-remarks=. \
|
2020-01-24 21:24:18 +01:00
|
|
|
; RUN: -whole-program-visibility \
|
2018-07-19 16:51:32 +02:00
|
|
|
; RUN: -o %t3 \
|
|
|
|
; RUN: -r=%t.o,test,px \
|
|
|
|
; RUN: -r=%t.o,_ZN1A1nEi,p \
|
|
|
|
; RUN: -r=%t.o,_ZN1B1fEi,p \
|
|
|
|
; RUN: -r=%t.o,_ZN1C1fEi,p \
|
2018-09-18 15:42:24 +02:00
|
|
|
; RUN: -r=%t.o,empty,p \
|
2018-07-19 16:51:32 +02:00
|
|
|
; RUN: -r=%t.o,_ZTV1B, \
|
|
|
|
; RUN: -r=%t.o,_ZTV1C, \
|
|
|
|
; RUN: -r=%t.o,_ZN1A1nEi, \
|
|
|
|
; RUN: -r=%t.o,_ZN1B1fEi, \
|
|
|
|
; RUN: -r=%t.o,_ZN1C1fEi, \
|
|
|
|
; RUN: -r=%t.o,_ZTV1B,px \
|
2019-02-14 22:22:50 +01:00
|
|
|
; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=REMARK
|
|
|
|
; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
|
2018-07-19 16:51:32 +02:00
|
|
|
|
|
|
|
; New PM
|
2018-08-14 05:00:16 +02:00
|
|
|
; RUN: llvm-lto2 run %t.o -save-temps -use-new-pm -pass-remarks=. \
|
2020-01-24 21:24:18 +01:00
|
|
|
; RUN: -whole-program-visibility \
|
2018-07-19 16:51:32 +02:00
|
|
|
; RUN: -o %t3 \
|
|
|
|
; RUN: -r=%t.o,test,px \
|
|
|
|
; RUN: -r=%t.o,_ZN1A1nEi,p \
|
|
|
|
; RUN: -r=%t.o,_ZN1B1fEi,p \
|
|
|
|
; RUN: -r=%t.o,_ZN1C1fEi,p \
|
2018-09-18 15:42:24 +02:00
|
|
|
; RUN: -r=%t.o,empty,p \
|
2018-07-19 16:51:32 +02:00
|
|
|
; RUN: -r=%t.o,_ZTV1B, \
|
|
|
|
; RUN: -r=%t.o,_ZTV1C, \
|
|
|
|
; RUN: -r=%t.o,_ZN1A1nEi, \
|
|
|
|
; RUN: -r=%t.o,_ZN1B1fEi, \
|
|
|
|
; RUN: -r=%t.o,_ZN1C1fEi, \
|
|
|
|
; RUN: -r=%t.o,_ZTV1B,px \
|
2019-02-14 22:22:50 +01:00
|
|
|
; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=REMARK
|
|
|
|
; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
|
2018-07-19 16:51:32 +02:00
|
|
|
|
2018-08-14 05:00:16 +02:00
|
|
|
; REMARK: single-impl: devirtualized a call to _ZN1A1nEi
|
|
|
|
|
[LTO] Record whether LTOUnit splitting is enabled in index
Summary:
Records in the module summary index whether the bitcode was compiled
with the option necessary to enable splitting the LTO unit
(e.g. -fsanitize=cfi, -fwhole-program-vtables, or -fsplit-lto-unit).
The information is passed down to the ModuleSummaryIndex builder via a
new module flag "EnableSplitLTOUnit", which is propagated onto a flag
on the summary index.
This is then used during the LTO link to check whether all linked
summaries were built with the same value of this flag. If not, an error
is issued when we detect a situation requiring whole program visibility
of the class hierarchy. This is the case when both of the following
conditions are met:
1) We are performing LowerTypeTests or Whole Program Devirtualization.
2) There are type tests or type checked loads in the code.
Note I have also changed the ThinLTOBitcodeWriter to also gate the
module splitting on the value of this flag.
Reviewers: pcc
Subscribers: ormris, mehdi_amini, Prazek, inglorion, eraman, steven_wu, dexonsmith, arphaman, dang, llvm-commits
Differential Revision: https://reviews.llvm.org/D53890
llvm-svn: 350948
2019-01-11 19:31:57 +01:00
|
|
|
; Next check that we emit an error when trying to LTO link this module
|
|
|
|
; containing an llvm.type.checked.load (with a split LTO Unit) with one
|
2019-02-14 22:22:50 +01:00
|
|
|
; that does not have a split LTO Unit. Use -thinlto-distributed-indexes
|
|
|
|
; to ensure it is being caught in the thin link.
|
[LTO] Record whether LTOUnit splitting is enabled in index
Summary:
Records in the module summary index whether the bitcode was compiled
with the option necessary to enable splitting the LTO unit
(e.g. -fsanitize=cfi, -fwhole-program-vtables, or -fsplit-lto-unit).
The information is passed down to the ModuleSummaryIndex builder via a
new module flag "EnableSplitLTOUnit", which is propagated onto a flag
on the summary index.
This is then used during the LTO link to check whether all linked
summaries were built with the same value of this flag. If not, an error
is issued when we detect a situation requiring whole program visibility
of the class hierarchy. This is the case when both of the following
conditions are met:
1) We are performing LowerTypeTests or Whole Program Devirtualization.
2) There are type tests or type checked loads in the code.
Note I have also changed the ThinLTOBitcodeWriter to also gate the
module splitting on the value of this flag.
Reviewers: pcc
Subscribers: ormris, mehdi_amini, Prazek, inglorion, eraman, steven_wu, dexonsmith, arphaman, dang, llvm-commits
Differential Revision: https://reviews.llvm.org/D53890
llvm-svn: 350948
2019-01-11 19:31:57 +01:00
|
|
|
; RUN: opt -thinlto-bc -o %t2.o %S/Inputs/empty.ll
|
2019-02-14 22:22:50 +01:00
|
|
|
; RUN: not llvm-lto2 run %t.o %t2.o -thinlto-distributed-indexes \
|
2020-01-24 21:24:18 +01:00
|
|
|
; RUN: -whole-program-visibility \
|
[LTO] Record whether LTOUnit splitting is enabled in index
Summary:
Records in the module summary index whether the bitcode was compiled
with the option necessary to enable splitting the LTO unit
(e.g. -fsanitize=cfi, -fwhole-program-vtables, or -fsplit-lto-unit).
The information is passed down to the ModuleSummaryIndex builder via a
new module flag "EnableSplitLTOUnit", which is propagated onto a flag
on the summary index.
This is then used during the LTO link to check whether all linked
summaries were built with the same value of this flag. If not, an error
is issued when we detect a situation requiring whole program visibility
of the class hierarchy. This is the case when both of the following
conditions are met:
1) We are performing LowerTypeTests or Whole Program Devirtualization.
2) There are type tests or type checked loads in the code.
Note I have also changed the ThinLTOBitcodeWriter to also gate the
module splitting on the value of this flag.
Reviewers: pcc
Subscribers: ormris, mehdi_amini, Prazek, inglorion, eraman, steven_wu, dexonsmith, arphaman, dang, llvm-commits
Differential Revision: https://reviews.llvm.org/D53890
llvm-svn: 350948
2019-01-11 19:31:57 +01:00
|
|
|
; RUN: -o %t3 \
|
|
|
|
; RUN: -r=%t.o,test,px \
|
|
|
|
; RUN: -r=%t.o,_ZN1A1nEi,p \
|
|
|
|
; RUN: -r=%t.o,_ZN1B1fEi,p \
|
|
|
|
; RUN: -r=%t.o,_ZN1C1fEi,p \
|
|
|
|
; RUN: -r=%t.o,empty,p \
|
|
|
|
; RUN: -r=%t.o,_ZTV1B, \
|
|
|
|
; RUN: -r=%t.o,_ZTV1C, \
|
|
|
|
; RUN: -r=%t.o,_ZN1A1nEi, \
|
|
|
|
; RUN: -r=%t.o,_ZN1B1fEi, \
|
|
|
|
; RUN: -r=%t.o,_ZN1C1fEi, \
|
|
|
|
; RUN: -r=%t.o,_ZTV1B,px \
|
2019-02-14 22:22:50 +01:00
|
|
|
; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=ERROR
|
|
|
|
; ERROR: failed: inconsistent LTO Unit splitting (recompile with -fsplit-lto-unit)
|
[LTO] Record whether LTOUnit splitting is enabled in index
Summary:
Records in the module summary index whether the bitcode was compiled
with the option necessary to enable splitting the LTO unit
(e.g. -fsanitize=cfi, -fwhole-program-vtables, or -fsplit-lto-unit).
The information is passed down to the ModuleSummaryIndex builder via a
new module flag "EnableSplitLTOUnit", which is propagated onto a flag
on the summary index.
This is then used during the LTO link to check whether all linked
summaries were built with the same value of this flag. If not, an error
is issued when we detect a situation requiring whole program visibility
of the class hierarchy. This is the case when both of the following
conditions are met:
1) We are performing LowerTypeTests or Whole Program Devirtualization.
2) There are type tests or type checked loads in the code.
Note I have also changed the ThinLTOBitcodeWriter to also gate the
module splitting on the value of this flag.
Reviewers: pcc
Subscribers: ormris, mehdi_amini, Prazek, inglorion, eraman, steven_wu, dexonsmith, arphaman, dang, llvm-commits
Differential Revision: https://reviews.llvm.org/D53890
llvm-svn: 350948
2019-01-11 19:31:57 +01:00
|
|
|
|
2019-09-11 01:15:38 +02:00
|
|
|
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
2018-07-19 16:51:32 +02:00
|
|
|
target triple = "x86_64-grtev4-linux-gnu"
|
|
|
|
|
|
|
|
%struct.A = type { i32 (...)** }
|
|
|
|
%struct.B = type { %struct.A }
|
|
|
|
%struct.C = type { %struct.A }
|
|
|
|
|
|
|
|
@_ZTV1B = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !1
|
|
|
|
@_ZTV1C = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.C*, i32)* @_ZN1C1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !2
|
|
|
|
|
2018-09-18 15:42:24 +02:00
|
|
|
; Put declaration first to test handling of remarks when the first
|
|
|
|
; function has no basic blocks.
|
|
|
|
declare void @empty()
|
|
|
|
|
2018-07-19 16:51:32 +02:00
|
|
|
; CHECK-IR-LABEL: define i32 @test
|
|
|
|
define i32 @test(%struct.A* %obj, i32 %a) {
|
|
|
|
entry:
|
|
|
|
%0 = bitcast %struct.A* %obj to i8**
|
|
|
|
%vtable5 = load i8*, i8** %0
|
|
|
|
|
|
|
|
%1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, metadata !"_ZTS1A")
|
|
|
|
%2 = extractvalue { i8*, i1 } %1, 1
|
|
|
|
br i1 %2, label %cont, label %trap
|
|
|
|
|
|
|
|
trap:
|
|
|
|
tail call void @llvm.trap()
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
cont:
|
|
|
|
%3 = extractvalue { i8*, i1 } %1, 0
|
|
|
|
%4 = bitcast i8* %3 to i32 (%struct.A*, i32)*
|
|
|
|
|
|
|
|
; Check that the call was devirtualized.
|
|
|
|
; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
|
|
|
|
%call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a)
|
|
|
|
%vtable16 = load i8*, i8** %0
|
|
|
|
%5 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable16, i32 0, metadata !"_ZTS1A")
|
|
|
|
%6 = extractvalue { i8*, i1 } %5, 1
|
|
|
|
br i1 %6, label %cont2, label %trap
|
|
|
|
|
|
|
|
cont2:
|
|
|
|
%7 = extractvalue { i8*, i1 } %5, 0
|
|
|
|
%8 = bitcast i8* %7 to i32 (%struct.A*, i32)*
|
|
|
|
|
|
|
|
; Check that traps are conditional. Invalid TYPE_ID can cause
|
|
|
|
; unconditional traps.
|
[InstCombine] Always try to invert non-canonical predicate of an icmp
Summary:
The actual transform i was going after was:
https://rise4fun.com/Alive/Tp9H
```
Name: zz
Pre: isPowerOf2(C0) && isPowerOf2(C1) && C1 == C0
%t0 = and i8 %x, C0
%r = icmp eq i8 %t0, C1
=>
%t = icmp eq i8 %t0, 0
%r = xor i1 %t, -1
Name: zz
Pre: isPowerOf2(C0)
%t0 = and i8 %x, C0
%r = icmp ne i8 %t0, 0
=>
%t = icmp eq i8 %t0, 0
%r = xor i1 %t, -1
```
but as it can be seen from the current tests, we already canonicalize most of it,
and we are only missing handling multi-use non-canonical icmp predicates.
If we have both `!=0` and `==0`, even though we can CSE them,
we end up being stuck with them. We should canonicalize to the `==0`.
I believe this is one of the cleanup steps i'll need after `-scalarizer`
if i end up proceeding with my WIP alloca promotion helper pass.
Reviewers: spatel, jdoerfert, nikic
Reviewed By: nikic
Subscribers: zzheng, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83139
2020-07-04 16:39:48 +02:00
|
|
|
; CHECK-IR: br i1 {{.*}}, label %trap, label %cont2
|
2018-07-19 16:51:32 +02:00
|
|
|
|
|
|
|
; We still have to call it as virtual.
|
[InstCombine] Always try to invert non-canonical predicate of an icmp
Summary:
The actual transform i was going after was:
https://rise4fun.com/Alive/Tp9H
```
Name: zz
Pre: isPowerOf2(C0) && isPowerOf2(C1) && C1 == C0
%t0 = and i8 %x, C0
%r = icmp eq i8 %t0, C1
=>
%t = icmp eq i8 %t0, 0
%r = xor i1 %t, -1
Name: zz
Pre: isPowerOf2(C0)
%t0 = and i8 %x, C0
%r = icmp ne i8 %t0, 0
=>
%t = icmp eq i8 %t0, 0
%r = xor i1 %t, -1
```
but as it can be seen from the current tests, we already canonicalize most of it,
and we are only missing handling multi-use non-canonical icmp predicates.
If we have both `!=0` and `==0`, even though we can CSE them,
we end up being stuck with them. We should canonicalize to the `==0`.
I believe this is one of the cleanup steps i'll need after `-scalarizer`
if i end up proceeding with my WIP alloca promotion helper pass.
Reviewers: spatel, jdoerfert, nikic
Reviewed By: nikic
Subscribers: zzheng, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83139
2020-07-04 16:39:48 +02:00
|
|
|
; CHECK-IR: %call3 = tail call i32 %7
|
2018-07-19 16:51:32 +02:00
|
|
|
%call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call)
|
|
|
|
ret i32 %call3
|
|
|
|
}
|
|
|
|
; CHECK-IR-LABEL: ret i32
|
|
|
|
; CHECK-IR-LABEL: }
|
|
|
|
|
|
|
|
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
|
|
|
|
declare void @llvm.trap()
|
|
|
|
|
|
|
|
declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a)
|
|
|
|
declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a)
|
|
|
|
declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a)
|
|
|
|
|
|
|
|
!0 = !{i64 16, !"_ZTS1A"}
|
|
|
|
!1 = !{i64 16, !"_ZTS1B"}
|
|
|
|
!2 = !{i64 16, !"_ZTS1C"}
|