Skip to content

Commit 167767a

Browse files
committed
SpeculativeExecution: Fix for logic change introduced in D81730.
Summary: The test case started to hoist bitcasts to upper BB after D81730. Reverted unintentional logic change. Some instructions may have zero cost but will not be hoisted by different limitation so should be counted for threshold. Reviewers: aprantl, arsenm, nhaehnle Reviewed By: aprantl Subscribers: wdng, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D82761
1 parent d36b841 commit 167767a

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,8 @@ bool SpeculativeExecutionPass::considerHoistingFromTo(
291291
if (TotalSpeculationCost > SpecExecMaxSpeculationCost)
292292
return false; // too much to hoist
293293
} else {
294-
// If the instruction cannot be hoisted but has zero cost suppose it's
295-
// a special case e.g. debug info instrinsics that should not be counted
296-
// for threshold.
297-
if (Cost)
294+
// Debug info instrinsics should not be counted for threshold.
295+
if (!isa<DbgInfoIntrinsic>(I))
298296
NotHoistedInstCount++;
299297
if (NotHoistedInstCount > SpecExecMaxNotHoisted)
300298
return false; // too much left behind

llvm/test/Transforms/SpeculativeExecution/PR46267.ll

+30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
; RUN: opt < %s -S -speculative-execution | FileCheck %s
22
; RUN: opt < %s -S -passes='speculative-execution' | FileCheck %s
33

4+
%class.B = type { i32 (...)** }
5+
6+
; Testing that two bitcasts are not hoisted to the first BB
7+
define i8* @foo(%class.B* readonly %b) {
8+
; CHECK-LABEL: foo
9+
; CHECK-LABEL: entry
10+
; CHECK-NEXT: %i = icmp eq %class.B* %b, null
11+
; CHECK-NEXT: br i1 %i, label %end, label %notnull
12+
entry:
13+
%i = icmp eq %class.B* %b, null
14+
br i1 %i, label %end, label %notnull
15+
16+
; CHECK-LABEL: notnull:
17+
; CHECK-NEXT: %i1 = bitcast %class.B* %b to i32**
18+
; CHECK: %i3 = bitcast %class.B* %b to i8*
19+
notnull: ; preds = %entry
20+
%i1 = bitcast %class.B* %b to i32**
21+
%vtable = load i32*, i32** %i1, align 8
22+
%i2 = getelementptr inbounds i32, i32* %vtable, i64 -2
23+
%offset.to.top = load i32, i32* %i2, align 4
24+
%i3 = bitcast %class.B* %b to i8*
25+
%i4 = sext i32 %offset.to.top to i64
26+
%i5 = getelementptr inbounds i8, i8* %i3, i64 %i4
27+
br label %end
28+
29+
end: ; preds = %notnull, %entry
30+
%i6 = phi i8* [ %i5, %notnull ], [ null, %entry ]
31+
ret i8* %i6
32+
}
33+
434
define void @f(i32 %i) {
535
entry:
636
; CHECK-LABEL: @f(

0 commit comments

Comments
 (0)