[PATCH] D91677: Avoid simplification of library functions when callee has an implementation

Siddhesh Poyarekar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 09:01:59 PST 2020


siddhesh updated this revision to Diff 306133.
siddhesh retitled this revision from "Avoid transforming fortified bcopy to memmove" to "Avoid simplification of library functions when callee has an implementation".
siddhesh edited the summary of this revision.
siddhesh added a comment.

Made the change more generic, avoiding simplification if the callee has an implementation, i.e. its body is not empty.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91677/new/

https://reviews.llvm.org/D91677

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/bcopy-chk.ll


Index: llvm/test/Transforms/InstCombine/bcopy-chk.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/bcopy-chk.ll
@@ -0,0 +1,27 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -O1 -S | FileCheck %s
+
+declare i8* @__memmove_chk(i8*, i8*, i64, i64)
+declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1, i1)
+
+define available_externally dso_local void @bcopy(i8* nocapture readonly %src, i8* nocapture %dst, i64 %len) #0 {
+  %size = call i64 @llvm.objectsize.i64.p0i8(i8* %dst, i1 false, i1 true, i1 false)
+  call i8* @__memmove_chk(i8* %dst, i8* %src, i64 %len, i64 %size)
+  ret void
+}
+
+ at buf = dso_local global [4 x i8] zeroinitializer, align 1
+
+define dso_local void @fortified_bcopy(i64 %argc) {
+; CHECK-LABEL: @fortified_bcopy(
+; CHECK-NEXT:    [[ADD:%.*]] = add i64 [[ARGC:%.*]], 1
+; CHECK-NEXT:    [[TMP1:%.*]] = call i8* @__memmove_chk(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @buf, i64 0, i64 2), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @buf, i64 0, i64 1), i64 [[ADD]], i64 2)
+; CHECK-NEXT:    ret void
+;
+  %add = add i64 %argc, 1
+  tail call void @bcopy(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @buf, i64 0, i64 1), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @buf, i64 0, i64 2), i64 %add) #1
+  ret void
+}
+
+attributes #0 = { alwaysinline }
+attributes #1 = { builtin }
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3073,6 +3073,11 @@
     }
   }
 
+  // Simplification is for external library calls, so bail out if the callee
+  // has an implementation.
+  if (!Callee->empty())
+    return nullptr;
+
   // Also try to simplify calls to fortified library functions.
   if (Value *SimplifiedFortifiedCI =
           FortifiedSimplifier.optimizeCall(CI, Builder)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91677.306133.patch
Type: text/x-patch
Size: 2020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201118/46a336c6/attachment.bin>


More information about the llvm-commits mailing list