[PATCH] D133730: [SimplifyCFG] Don't hoist inalloca allocas
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 12 15:10:05 PDT 2022
aeubanks created this revision.
Herald added subscribers: asbirlea, george.burgess.iv, hiraditya.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
D129370 <https://reviews.llvm.org/D129370> started hoisting inalloca allocas across stacksave/stackrestore
boundaries which is wrong.
I looked into treating inalloca allocas implying
`I->mayHaveSideEffects()`, but that breaks various things like MemorySSA
and SLPVectorizer so I stuck with the status quo and special cased this.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133730
Files:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/hoist-common-skip.ll
Index: llvm/test/Transforms/SimplifyCFG/hoist-common-skip.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/hoist-common-skip.ll
+++ llvm/test/Transforms/SimplifyCFG/hoist-common-skip.ll
@@ -392,19 +392,21 @@
define void @f10(i1 %cond) {
; CHECK-LABEL: @f10(
; CHECK-NEXT: [[SS:%.*]] = call ptr @llvm.stacksave()
-; CHECK-NEXT: [[SS2:%.*]] = call ptr @llvm.stacksave()
-; CHECK-NEXT: [[I2:%.*]] = alloca inalloca i64, align 8
; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: [[I1:%.*]] = alloca inalloca i32, align 4
+; CHECK-NEXT: [[SS2:%.*]] = call ptr @llvm.stacksave()
+; CHECK-NEXT: [[I2:%.*]] = alloca inalloca i64, align 8
; CHECK-NEXT: call void @inalloca_i64(ptr inalloca(i64) [[I2]])
; CHECK-NEXT: call void @llvm.stackrestore(ptr [[SS2]])
; CHECK-NEXT: call void @inalloca_i32(ptr inalloca(i32) [[I1]])
; CHECK-NEXT: br label [[END:%.*]]
; CHECK: bb2:
; CHECK-NEXT: [[I3:%.*]] = alloca inalloca i64, align 8
-; CHECK-NEXT: [[TMP1:%.*]] = call ptr @inalloca_i64(ptr inalloca(i64) [[I2]])
-; CHECK-NEXT: call void @llvm.stackrestore(ptr [[SS2]])
+; CHECK-NEXT: [[SS3:%.*]] = call ptr @llvm.stacksave()
+; CHECK-NEXT: [[I4:%.*]] = alloca inalloca i64, align 8
+; CHECK-NEXT: [[TMP1:%.*]] = call ptr @inalloca_i64(ptr inalloca(i64) [[I4]])
+; CHECK-NEXT: call void @llvm.stackrestore(ptr [[SS3]])
; CHECK-NEXT: [[TMP2:%.*]] = call ptr @inalloca_i64(ptr inalloca(i64) [[I3]])
; CHECK-NEXT: br label [[END]]
; CHECK: end:
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1442,7 +1442,11 @@
unsigned Flags = 0;
if (I->mayReadFromMemory())
Flags |= SkipReadMem;
- if (I->mayHaveSideEffects())
+ // For the purposes of hoisting instructions, inalloca allocas are treated as
+ // having side effects to avoid moving them across stacksave/stackrestore
+ // boundaries.
+ if (I->mayHaveSideEffects() ||
+ (isa<AllocaInst>(I) && cast<AllocaInst>(I)->isUsedWithInAlloca()))
Flags |= SkipSideEffect;
if (!isGuaranteedToTransferExecutionToSuccessor(I))
Flags |= SkipImplicitControlFlow;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133730.459569.patch
Type: text/x-patch
Size: 2381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220912/93dfc2d2/attachment.bin>
More information about the llvm-commits
mailing list