From a87738f86b17f4a8dcde538c60826506e2a27ed1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 8 Dec 2023 17:15:51 +0100 Subject: [AutoUpgrade] Don't try to upgrade struct return of non-intrinsic This code should only be run for intrinsics known to LLVM (otherwise it will crash), not for everything that starts with "llvm.". --- llvm/lib/IR/AutoUpgrade.cpp | 3 ++- llvm/test/Assembler/struct-ret-without-upgrade.ll | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 67ee7b7..645691f 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -1293,7 +1293,8 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) { } auto *ST = dyn_cast(F->getReturnType()); - if (ST && (!ST->isLiteral() || ST->isPacked())) { + if (ST && (!ST->isLiteral() || ST->isPacked()) && + F->getIntrinsicID() != Intrinsic::not_intrinsic) { // Replace return type with literal non-packed struct. Only do this for // intrinsics declared to return a struct, not for intrinsics with // overloaded return type, in which case the exact struct type will be diff --git a/llvm/test/Assembler/struct-ret-without-upgrade.ll b/llvm/test/Assembler/struct-ret-without-upgrade.ll index 992b2f9..14f931c 100644 --- a/llvm/test/Assembler/struct-ret-without-upgrade.ll +++ b/llvm/test/Assembler/struct-ret-without-upgrade.ll @@ -15,4 +15,15 @@ define %ty @test(%ty %arg) { ret %ty %copy } +define %ty @test_not_real_intrinsic() { +; CHECK-LABEL: @test_not_real_intrinsic( +; CHECK-NEXT: [[RET:%.*]] = call [[TY:%.*]] @llvm.dummy() +; CHECK-NEXT: ret [[TY]] [[RET]] +; + %ret = call %ty @llvm.dummy() + ret %ty %ret +} + +declare %ty @llvm.dummy() + declare %ty @llvm.ssa.copy.s_tys(%ty) -- cgit v1.1