Skip to content

Commit 21a9060

Browse files
nikicJaddyen
authored andcommitted
[SimplifyCFG] Only consider provenance capture in store speculation (llvm#138548)
The capture check here is to protect against concurrent accesses from other threads. This requires the provenance to escape.
1 parent a5c9809 commit 21a9060

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
@@ -3067,7 +3067,9 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB,
30673067
Value *Obj = getUnderlyingObject(StorePtr);
30683068
bool ExplicitlyDereferenceableOnly;
30693069
if (isWritableObject(Obj, ExplicitlyDereferenceableOnly) &&
3070-
!PointerMayBeCaptured(Obj, /*ReturnCaptures=*/false) &&
3070+
capturesNothing(
3071+
PointerMayBeCaptured(Obj, /*ReturnCaptures=*/false,
3072+
CaptureComponents::Provenance)) &&
30713073
(!ExplicitlyDereferenceableOnly ||
30723074
isDereferenceablePointer(StorePtr, StoreTy,
30733075
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)