Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -10042,8 +10042,10 @@ } // In addition to the cases handle just above, we need to prevent - // allocas and loads/stores from moving below a stacksave. The - // stackrestore case is currently thought to be conservatism. + // allocas and loads/stores from moving below a stacksave or a + // stackrestore. Avoiding moving allocas below stackrestore is currently + // thought to be conservatism. Moving loads/stores below a stackrestore + // can lead to incorrect code. if (isa(BundleMember->Inst) || BundleMember->Inst->mayReadOrWriteMemory()) { for (Instruction *I = BundleMember->Inst->getNextNode(); Index: llvm/test/Transforms/SLPVectorizer/X86/stackrestore-dependence.ll =================================================================== --- llvm/test/Transforms/SLPVectorizer/X86/stackrestore-dependence.ll +++ llvm/test/Transforms/SLPVectorizer/X86/stackrestore-dependence.ll @@ -1,7 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -passes=slp-vectorizer -slp-threshold=-999 -mtriple=x86_64-unknown-linux-gnu -mcpu=skylake -S < %s | FileCheck %s -; The tests checks that loads should not be moved below a stackrestore boundary. +; The test checks that loads should not be moved below a stackrestore boundary. define void @stackrestore1(ptr %out) { ; CHECK-LABEL: @stackrestore1( ; CHECK-NEXT: [[STACK:%.*]] = call ptr @llvm.stacksave()