From 532d022794beabceae09c7fcc222a6e4e929c748 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Fri, 1 Feb 2008 20:37:16 +0000 Subject: [PATCH] Don't drop function/call return attributes like 'nounwind'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46645 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/ArgumentPromotion.cpp | 8 ++++++++ .../ArgumentPromotion/2008-02-01-ReturnAttrs.ll | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/Transforms/ArgumentPromotion/2008-02-01-ReturnAttrs.ll diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 3ac1c7bb2b2..4486677e630 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -404,6 +404,10 @@ Function *ArgPromotion::DoPromotion(Function *F, ParamAttrsVector ParamAttrsVec; const ParamAttrsList *PAL = F->getParamAttrs(); + // Add any return attributes. + if (unsigned attrs = PAL ? PAL->getParamAttrs(0) : 0) + ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs)); + unsigned ArgIndex = 1; for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I, ++ArgIndex) { @@ -491,6 +495,10 @@ Function *ArgPromotion::DoPromotion(Function *F, Instruction *Call = CS.getInstruction(); PAL = CS.getParamAttrs(); + // Add any return attributes. + if (unsigned attrs = PAL ? PAL->getParamAttrs(0) : 0) + ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs)); + // Loop over the operands, inserting GEP and loads in the caller as // appropriate. CallSite::arg_iterator AI = CS.arg_begin(); diff --git a/test/Transforms/ArgumentPromotion/2008-02-01-ReturnAttrs.ll b/test/Transforms/ArgumentPromotion/2008-02-01-ReturnAttrs.ll new file mode 100644 index 00000000000..67c061fc1ca --- /dev/null +++ b/test/Transforms/ArgumentPromotion/2008-02-01-ReturnAttrs.ll @@ -0,0 +1,15 @@ +; RUN: llvm-as < %s | opt -argpromotion | llvm-dis | grep nounwind | count 2 + +define internal i32 @deref(i32* %x) nounwind { +entry: + %tmp2 = load i32* %x, align 4 ; [#uses=1] + ret i32 %tmp2 +} + +define i32 @f(i32 %x) { +entry: + %x_addr = alloca i32 ; [#uses=2] + store i32 %x, i32* %x_addr, align 4 + %tmp1 = call i32 @deref( i32* %x_addr ) nounwind ; [#uses=1] + ret i32 %tmp1 +}