Skip to content

Commit 49afe1b

Browse files
committed
[SimplifyCFG] Only consider provenance capture in store speculation
The capture check here is to protect against concurrent accesses from other threads. This requires the provenance to escape.
1 parent a7bff2a commit 49afe1b

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3057,7 +3057,9 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB,
30573057
Value *Obj = getUnderlyingObject(StorePtr);
30583058
bool ExplicitlyDereferenceableOnly;
30593059
if (isWritableObject(Obj, ExplicitlyDereferenceableOnly) &&
3060-
!PointerMayBeCaptured(Obj, /*ReturnCaptures=*/false) &&
3060+
capturesNothing(
3061+
PointerMayBeCaptured(Obj, /*ReturnCaptures=*/false,
3062+
CaptureComponents::Provenance)) &&
30613063
(!ExplicitlyDereferenceableOnly ||
30623064
isDereferenceablePointer(StorePtr, StoreTy,
30633065
LI->getDataLayout()))) {

llvm/test/Transforms/SimplifyCFG/speculate-store.ll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,8 @@ define i32 @load_before_store_escape_addr_only(i64 %i, i32 %b) {
203203
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2 x i32], ptr [[A]], i64 0, i64 [[I:%.*]]
204204
; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
205205
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[TMP0]], [[B:%.*]]
206-
; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
207-
; CHECK: if.then:
208-
; CHECK-NEXT: store i32 [[B]], ptr [[ARRAYIDX]], align 4
209-
; CHECK-NEXT: br label [[IF_END]]
210-
; CHECK: if.end:
206+
; CHECK-NEXT: [[SPEC_STORE_SELECT:%.*]] = select i1 [[CMP]], i32 [[B]], i32 [[TMP0]]
207+
; CHECK-NEXT: store i32 [[SPEC_STORE_SELECT]], ptr [[ARRAYIDX]], align 4
211208
; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[A]], align 4
212209
; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds [2 x i32], ptr [[A]], i64 0, i64 1
213210
; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4

0 commit comments

Comments
 (0)