mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
cd98794503
Summary: Readnone attribute would cause CSE of two barriers with the same argument, which is invalid by example: struct Base { virtual int foo() { return 42; } }; struct Derived1 : Base { int foo() override { return 50; } }; struct Derived2 : Base { int foo() override { return 100; } }; void foo() { Base *x = new Base{}; new (x) Derived1{}; int a = std::launder(x)->foo(); new (x) Derived2{}; int b = std::launder(x)->foo(); } Here 2 calls of std::launder will produce @llvm.invariant.group.barrier, which would be merged into one call, causing devirtualization to devirtualize second call into Derived1::foo() instead of Derived2::foo() Reviewers: chandlerc, dberlin, hfinkel Subscribers: llvm-commits, rsmith, amharc Differential Revision: https://reviews.llvm.org/D31531 llvm-svn: 300101
63 lines
2.0 KiB
LLVM
63 lines
2.0 KiB
LLVM
; RUN: opt -S -early-cse < %s | FileCheck %s
|
|
; RUN: opt -S -gvn < %s | FileCheck %s
|
|
; RUN: opt -S -newgvn < %s | FileCheck %s
|
|
; RUN: opt -S -O3 < %s | FileCheck %s
|
|
|
|
; These tests checks if passes with CSE functionality can do CSE on
|
|
; invariant.group.barrier, that is prohibited if there is a memory clobber
|
|
; between barriers call.
|
|
|
|
; CHECK-LABEL: define i8 @optimizable()
|
|
define i8 @optimizable() {
|
|
entry:
|
|
%ptr = alloca i8
|
|
store i8 42, i8* %ptr, !invariant.group !0
|
|
; CHECK: call i8* @llvm.invariant.group.barrier
|
|
%ptr2 = call i8* @llvm.invariant.group.barrier(i8* %ptr)
|
|
; CHECK-NOT: call i8* @llvm.invariant.group.barrier
|
|
%ptr3 = call i8* @llvm.invariant.group.barrier(i8* %ptr)
|
|
; CHECK: call void @clobber(i8* {{.*}}%ptr)
|
|
call void @clobber(i8* %ptr)
|
|
|
|
; CHECK: call void @use(i8* {{.*}}%ptr2)
|
|
call void @use(i8* %ptr2)
|
|
; CHECK: call void @use(i8* {{.*}}%ptr2)
|
|
call void @use(i8* %ptr3)
|
|
; CHECK: load i8, i8* %ptr2, {{.*}}!invariant.group
|
|
%v = load i8, i8* %ptr3, !invariant.group !0
|
|
|
|
ret i8 %v
|
|
}
|
|
|
|
; CHECK-LABEL: define i8 @unoptimizable()
|
|
define i8 @unoptimizable() {
|
|
entry:
|
|
%ptr = alloca i8
|
|
store i8 42, i8* %ptr, !invariant.group !0
|
|
; CHECK: call i8* @llvm.invariant.group.barrier
|
|
%ptr2 = call i8* @llvm.invariant.group.barrier(i8* %ptr)
|
|
call void @clobber(i8* %ptr)
|
|
; CHECK: call i8* @llvm.invariant.group.barrier
|
|
%ptr3 = call i8* @llvm.invariant.group.barrier(i8* %ptr)
|
|
; CHECK: call void @clobber(i8* {{.*}}%ptr)
|
|
call void @clobber(i8* %ptr)
|
|
; CHECK: call void @use(i8* {{.*}}%ptr2)
|
|
call void @use(i8* %ptr2)
|
|
; CHECK: call void @use(i8* {{.*}}%ptr3)
|
|
call void @use(i8* %ptr3)
|
|
; CHECK: load i8, i8* %ptr3, {{.*}}!invariant.group
|
|
%v = load i8, i8* %ptr3, !invariant.group !0
|
|
|
|
ret i8 %v
|
|
}
|
|
|
|
declare void @use(i8* readonly)
|
|
|
|
declare void @clobber(i8*)
|
|
; CHECK: Function Attrs: argmemonly nounwind readonly
|
|
; CHECK-NEXT: declare i8* @llvm.invariant.group.barrier(i8*)
|
|
declare i8* @llvm.invariant.group.barrier(i8*)
|
|
|
|
!0 = !{}
|
|
|