InstCombineCalls: when adding an align attribute, never reduce it

Sometimes we can infer an align from an allocalign but the function
already promised it'd be more-aligned than the allocalign and there's an
existing align that we shouldn't reduce. Make sure we handle that
correctly.

Differential Revision: https://reviews.llvm.org/D121642
This commit is contained in:
Augie Fackler 2022-03-14 16:25:56 -04:00
parent 5f09498a11
commit f120be6c86
2 changed files with 7 additions and 6 deletions

View file

@ -2837,9 +2837,12 @@ void InstCombinerImpl::annotateAnyAllocSite(CallBase &Call, const TargetLibraryI
if (AlignOpC && AlignOpC->getValue().ult(llvm::Value::MaximumAlignment)) {
uint64_t AlignmentVal = AlignOpC->getZExtValue();
if (llvm::isPowerOf2_64(AlignmentVal)) {
Call.removeRetAttr(Attribute::Alignment);
Call.addRetAttr(Attribute::getWithAlignment(Call.getContext(),
Align(AlignmentVal)));
Align ExistingAlign = Call.getRetAlign().valueOrOne();
Align NewAlign = Align(AlignmentVal);
if (NewAlign > ExistingAlign) {
Call.addRetAttr(
Attribute::getWithAlignment(Call.getContext(), NewAlign));
}
}
}
}

View file

@ -26,12 +26,10 @@ entry:
ret i8* %call
}
; BUG: we shouldn't narrow this alignment since we already had a stronger
; constraint, but we do.
define i8* @dont_narrow_align_from_allocalign() {
; CHECK-LABEL: @dont_narrow_align_from_allocalign(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CALL:%.*]] = tail call align 8 i8* @my_aligned_alloc(i32 noundef 320, i32 noundef 8)
; CHECK-NEXT: [[CALL:%.*]] = tail call align 16 i8* @my_aligned_alloc(i32 noundef 320, i32 noundef 8)
; CHECK-NEXT: ret i8* [[CALL]]
;
entry: