llvm-project/llvm/test/Transforms/SimplifyCFG/no-md-sink.ll

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.3 KiB
LLVM
Raw Normal View History

; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -sink-common-insts -S | FileCheck %s
; RUN: opt < %s -passes='simplify-cfg<sink-common-insts>' -S | FileCheck %s
define i1 @test1(i1 zeroext %flag, i8* %y) #0 {
entry:
br i1 %flag, label %if.then, label %if.else
if.then:
%r = call i1 @llvm.type.test(i8* %y, metadata !0)
br label %if.end
if.else:
%s = call i1 @llvm.type.test(i8* %y, metadata !1)
br label %if.end
if.end:
%t = phi i1 [ %s, %if.else ], [ %r, %if.then ]
ret i1 %t
}
!0 = !{i32 0, !"typeid1"}
!1 = !{i32 4, !"typeid1"}
declare i1 @llvm.type.test(i8* %ptr, metadata %bitset) nounwind readnone
; CHECK-LABEL: test1
; CHECK: @llvm.type.test
; CHECK: @llvm.type.test
; CHECK: ret i1
define i1 @test2(i1 zeroext %flag, i8* %y, i8* %z) #0 {
entry:
br i1 %flag, label %if.then, label %if.else
if.then:
%r = call i1 @llvm.type.test(i8* %y, metadata !0)
br label %if.end
if.else:
%s = call i1 @llvm.type.test(i8* %z, metadata !0)
br label %if.end
if.end:
%t = phi i1 [ %s, %if.else ], [ %r, %if.then ]
ret i1 %t
}
; CHECK-LABEL: test2
; CHECK: %[[S:[a-z0-9.]+]] = select i1 %flag, i8* %y, i8* %z
Mark type test intrinsics as speculatable to fix inline cost 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. Differential Revision: https://reviews.llvm.org/D101180
2021-04-24 00:30:28 +08:00
; CHECK: %[[R:[a-z0-9.]+]] = call i1 @llvm.type.test(i8* %[[S]], metadata ![[MD:[0-9]+]]
; CHECK: ret i1 %[[R]]
Mark type test intrinsics as speculatable to fix inline cost 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. Differential Revision: https://reviews.llvm.org/D101180
2021-04-24 00:30:28 +08:00
; CHECK: ![[MD]] = !{i32 0, !"typeid1"}