@@ -85,7 +85,6 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
8585 TLI = MF->getSubtarget ().getTargetLowering ();
8686 RegInfo = &MF->getRegInfo ();
8787 const TargetFrameLowering *TFI = MF->getSubtarget ().getFrameLowering ();
88- unsigned StackAlign = TFI->getStackAlignment ();
8988 DA = DAG->getDivergenceAnalysis ();
9089
9190 // Check whether the function can return without sret-demotion.
@@ -130,19 +129,19 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
130129 // Initialize the mapping of values to registers. This is only set up for
131130 // instruction values that are used outside of the block that defines
132131 // them.
132+ const Align StackAlign = TFI->getStackAlign ();
133133 for (const BasicBlock &BB : *Fn) {
134134 for (const Instruction &I : BB) {
135135 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
136136 Type *Ty = AI->getAllocatedType ();
137- unsigned Align =
138- std::max ((unsigned )MF->getDataLayout ().getPrefTypeAlignment (Ty),
139- AI->getAlignment ());
137+ Align Alignment =
138+ max (MF->getDataLayout ().getPrefTypeAlign (Ty), AI->getAlign ());
140139
141140 // Static allocas can be folded into the initial stack frame
142141 // adjustment. For targets that don't realign the stack, don't
143142 // do this if there is an extra alignment requirement.
144143 if (AI->isStaticAlloca () &&
145- (TFI->isStackRealignable () || (Align <= StackAlign))) {
144+ (TFI->isStackRealignable () || (Alignment <= StackAlign))) {
146145 const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize ());
147146 uint64_t TySize =
148147 MF->getDataLayout ().getTypeAllocSize (Ty).getKnownMinSize ();
@@ -154,10 +153,10 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
154153 if (Iter != CatchObjects.end () && TLI->needsFixedCatchObjects ()) {
155154 FrameIndex = MF->getFrameInfo ().CreateFixedObject (
156155 TySize, 0 , /* IsImmutable=*/ false , /* isAliased=*/ true );
157- MF->getFrameInfo ().setObjectAlignment (FrameIndex, Align );
156+ MF->getFrameInfo ().setObjectAlignment (FrameIndex, Alignment );
158157 } else {
159- FrameIndex =
160- MF-> getFrameInfo (). CreateStackObject (TySize, Align, false , AI);
158+ FrameIndex = MF-> getFrameInfo (). CreateStackObject (TySize, Alignment,
159+ false , AI);
161160 }
162161
163162 // Scalable vectors may need a special StackID to distinguish
@@ -176,10 +175,9 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
176175 // FIXME: Overaligned static allocas should be grouped into
177176 // a single dynamic allocation instead of using a separate
178177 // stack allocation for each one.
179- if (Align <= StackAlign)
180- Align = 0 ;
181178 // Inform the Frame Information that we have variable-sized objects.
182- MF->getFrameInfo ().CreateVariableSizedObject (Align ? Align : 1 , AI);
179+ MF->getFrameInfo ().CreateVariableSizedObject (
180+ Alignment <= StackAlign ? 0 : Alignment.value (), AI);
183181 }
184182 }
185183
0 commit comments