[PATCH] D121642: InstCombineCalls: when adding an align attribute, never reduce it
Augie Fackler via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 7 07:36:13 PDT 2022
durin42 updated this revision to Diff 421202.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121642/new/
https://reviews.llvm.org/D121642
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/InferAlignAttribute.ll
Index: llvm/test/Transforms/InstCombine/InferAlignAttribute.ll
===================================================================
--- llvm/test/Transforms/InstCombine/InferAlignAttribute.ll
+++ llvm/test/Transforms/InstCombine/InferAlignAttribute.ll
@@ -26,12 +26,10 @@
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:
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2837,9 +2837,12 @@
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));
+ }
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121642.421202.patch
Type: text/x-patch
Size: 1682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220407/65c7e544/attachment.bin>
More information about the llvm-commits
mailing list