[llvm] 5a33d1f - [SimplifyCFG] Don't hoist allocas

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 09:23:51 PDT 2022


Author: Arthur Eubanks
Date: 2022-09-13T09:23:39-07:00
New Revision: 5a33d1f0b9434cdbab6d5f2134a9858762c832c9

URL: https://github.com/llvm/llvm-project/commit/5a33d1f0b9434cdbab6d5f2134a9858762c832c9
DIFF: https://github.com/llvm/llvm-project/commit/5a33d1f0b9434cdbab6d5f2134a9858762c832c9.diff

LOG: [SimplifyCFG] Don't hoist allocas

D129370 started hoisting allocas across stacksave/stackrestore
boundaries which is wrong.

Reviewed By: chill, rnk

Differential Revision: https://reviews.llvm.org/D133730

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/test/Transforms/SimplifyCFG/hoist-common-skip.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 49ecd988dba72..fcdd85838340d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1442,7 +1442,9 @@ static unsigned skippedInstrFlags(Instruction *I) {
   unsigned Flags = 0;
   if (I->mayReadFromMemory())
     Flags |= SkipReadMem;
-  if (I->mayHaveSideEffects())
+  // We can't arbitrarily move around allocas, e.g. moving allocas (especially
+  // inalloca) across stacksave/stackrestore boundaries.
+  if (I->mayHaveSideEffects() || isa<AllocaInst>(I))
     Flags |= SkipSideEffect;
   if (!isGuaranteedToTransferExecutionToSuccessor(I))
     Flags |= SkipImplicitControlFlow;

diff  --git a/llvm/test/Transforms/SimplifyCFG/hoist-common-skip.ll b/llvm/test/Transforms/SimplifyCFG/hoist-common-skip.ll
index 273f8573a177d..5b6eeda7c7847 100644
--- a/llvm/test/Transforms/SimplifyCFG/hoist-common-skip.ll
+++ b/llvm/test/Transforms/SimplifyCFG/hoist-common-skip.ll
@@ -388,23 +388,24 @@ if.end:
 }
 
 ;; Don't hoist stacksaves across inalloca allocas
-;; FIXME: currently this is miscompiled
 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:


        


More information about the llvm-commits mailing list