[llvm] r175470 - Check to see if the 'no-builtin' attribute is set before simplifying a library call.

Bill Wendling isanbard at gmail.com
Mon Feb 18 15:17:16 PST 2013


Author: void
Date: Mon Feb 18 17:17:16 2013
New Revision: 175470

URL: http://llvm.org/viewvc/llvm-project?rev=175470&view=rev
Log:
Check to see if the 'no-builtin' attribute is set before simplifying a library call.

Added:
    llvm/trunk/test/Transforms/InstCombine/no-builtin.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=175470&r1=175469&r2=175470&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Mon Feb 18 17:17:16 2013
@@ -1889,6 +1889,9 @@ LibCallSimplifier::~LibCallSimplifier()
 }
 
 Value *LibCallSimplifier::optimizeCall(CallInst *CI) {
+  Function *F = CI->getParent()->getParent();
+  // We don't want to "optimize" if the function doesn't want builtins.
+  if (F->hasFnAttribute("no-builtin")) return 0;
   return Impl->optimizeCall(CI);
 }
 

Added: llvm/trunk/test/Transforms/InstCombine/no-builtin.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/no-builtin.ll?rev=175470&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/no-builtin.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/no-builtin.ll Mon Feb 18 17:17:16 2013
@@ -0,0 +1,23 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+ at .str = private unnamed_addr constant [14 x i8] c"hello world!\0A\00", align 1
+
+; CHECK: @foo
+; CHECK: printf
+define void @foo() nounwind ssp uwtable "no-builtin" {
+entry:
+  %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0))
+  ret void
+}
+
+; CHECK: @bar
+; CHECK: puts
+define void @bar() nounwind ssp uwtable {
+entry:
+  %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0))
+  ret void
+}
+
+declare i32 @printf(i8*, ...)
+
+attributes #0 = { nounwind ssp uwtable "no-builtin" }
+attributes #1 = { nounwind ssp uwtable }





More information about the llvm-commits mailing list