[PATCH] D45180: libcalls must check for "RtLibUseGOT" metadata during simplification
Sriraman Tallam via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 5 09:48:13 PDT 2018
tmsriram updated this revision to Diff 141173.
tmsriram added a comment.
Simplify patch to get Module from F.getParent()
https://reviews.llvm.org/D45180
Files:
lib/Transforms/Utils/BuildLibCalls.cpp
test/CodeGen/X86/no-plt-libcalls.ll
Index: test/CodeGen/X86/no-plt-libcalls.ll
===================================================================
--- test/CodeGen/X86/no-plt-libcalls.ll
+++ test/CodeGen/X86/no-plt-libcalls.ll
@@ -0,0 +1,19 @@
+; Check if "RtLibUseGOT" works correctly when lib calls are simplified.
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+ at percent_s = constant [4 x i8] c"%s\0A\00"
+ at hello_world = constant [13 x i8] c"hello world\0A\00"
+declare i32 @printf(i8*, ...)
+define void @printf_call() {
+ %fmt = getelementptr [4 x i8], [4 x i8]* @percent_s, i32 0, i32 0
+ %str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0
+ call i32 (i8*, ...) @printf(i8* %fmt, i8* %str)
+; CHECK: call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i64 0, i64 0))
+ ret void
+}
+
+; CHECK: Function Attrs: nounwind nonlazybind
+; CHECK-NEXT: declare i32 @puts(i8* nocapture readonly)
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"RtLibUseGOT", i32 1}
Index: lib/Transforms/Utils/BuildLibCalls.cpp
===================================================================
--- lib/Transforms/Utils/BuildLibCalls.cpp
+++ lib/Transforms/Utils/BuildLibCalls.cpp
@@ -105,12 +105,23 @@
return true;
}
+static bool setNonLazyBind(Function &F) {
+ if (F.hasFnAttribute(Attribute::NonLazyBind))
+ return false;
+ F.addFnAttr(Attribute::NonLazyBind);
+ return true;
+}
+
bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
LibFunc TheLibFunc;
if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
return false;
bool Changed = false;
+
+ if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
+ Changed |= setNonLazyBind(F);
+
switch (TheLibFunc) {
case LibFunc_strlen:
case LibFunc_wcslen:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45180.141173.patch
Type: text/x-patch
Size: 1787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180405/63becc82/attachment.bin>
More information about the llvm-commits
mailing list