Skip to content

Commit

Permalink
[AutoUpgrade] Preserve attributes when upgrading named struct return
Browse files Browse the repository at this point in the history
For example, if the argument has an alignment attribute, preserve it.
  • Loading branch information
nikic committed Sep 2, 2024
1 parent 7519755 commit 5dcea46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4330,7 +4330,8 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
"Must have same number of elements");

SmallVector<Value *> Args(CI->args());
Value *NewCI = Builder.CreateCall(NewFn, Args);
CallInst *NewCI = Builder.CreateCall(NewFn, Args);
NewCI->setAttributes(CI->getAttributes());
Value *Res = PoisonValue::get(OldST);
for (unsigned Idx = 0; Idx < OldST->getNumElements(); ++Idx) {
Value *Elem = Builder.CreateExtractValue(NewCI, Idx);
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/Bitcode/intrinsics-struct-upgrade-attributes.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; RUN: llvm-as < %s | llvm-dis | FileCheck %s

%struct.__neon_int8x8x2_t = type { <8 x i8>, <8 x i8> }

declare %struct.__neon_int8x8x2_t @llvm.aarch64.neon.ld2.v8i8.p0i8(i8*)

; CHECK-LABEL: define %struct.__neon_int8x8x2_t @test_named_struct_return(ptr %A) {
; CHECK: %1 = call { <8 x i8>, <8 x i8> } @llvm.aarch64.neon.ld2.v8i8.p0(ptr align 16 %A)
; CHECK: %2 = extractvalue { <8 x i8>, <8 x i8> } %1, 0
; CHECK: %3 = insertvalue %struct.__neon_int8x8x2_t poison, <8 x i8> %2, 0
; CHECK: %4 = extractvalue { <8 x i8>, <8 x i8> } %1, 1
; CHECK: %5 = insertvalue %struct.__neon_int8x8x2_t %3, <8 x i8> %4, 1
; CHECK: ret %struct.__neon_int8x8x2_t %5

define %struct.__neon_int8x8x2_t @test_named_struct_return(ptr %A) {
%val = call %struct.__neon_int8x8x2_t @llvm.aarch64.neon.ld2.v8i8.p0i8(ptr align 16 %A)
ret %struct.__neon_int8x8x2_t %val
}

0 comments on commit 5dcea46

Please sign in to comment.