Skip to content

Commit

Permalink
InstCombineCalls: when adding an align attribute, never reduce it
Browse files Browse the repository at this point in the history
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
  • Loading branch information
durin42 committed Apr 7, 2022
1 parent 5f09498 commit f120be6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 6 additions & 3 deletions llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Expand Up @@ -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));
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions llvm/test/Transforms/InstCombine/InferAlignAttribute.ll
Expand Up @@ -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:
Expand Down

0 comments on commit f120be6

Please sign in to comment.