<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi David,<div class=""><br class=""></div><div class="">This commit seems to cause several bot failures:</div><div class=""><br class=""></div><div class=""><a href="http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental/48283/" class="">http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental/48283/</a></div><div class=""><br class=""></div><div class="">Could you take a look, and either revert or address the issues?</div><div class=""><br class=""></div><div class="">thanks,</div><div class="">vedant</div><div class=""><pre style="word-wrap: break-word; white-space: pre-wrap;" class="">Failing Tests (4):
    LLVM-Unit :: Analysis/./AnalysisTests/TargetLibraryInfoTest.ValidProto
    LLVM :: ThinLTO/X86/tli-nobuiltin.ll
    LLVM :: Transforms/InstCombine/fprintf-1.ll
    LLVM :: Transforms/InstCombine/fputs-1.ll</pre><div class=""><br class=""></div><div class=""><pre style="word-wrap: break-word; white-space: pre-wrap;" class="">FAIL: LLVM-Unit :: Analysis/./AnalysisTests/TargetLibraryInfoTest.ValidProto (1081 of 37556)
******************** TEST 'LLVM-Unit :: Analysis/./AnalysisTests/TargetLibraryInfoTest.ValidProto' FAILED ********************
Note: Google Test filter = TargetLibraryInfoTest.ValidProto
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from TargetLibraryInfoTest
[ RUN      ] TargetLibraryInfoTest.ValidProto
/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp:541: Failure
Value of: isLibFunc(F, LF)
  Actual: false (fgetc_unlocked not found)
Expected: true
/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp:541: Failure
Value of: isLibFunc(F, LF)
  Actual: false (fgets_unlocked not found)
Expected: true
/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp:541: Failure
Value of: isLibFunc(F, LF)
  Actual: false (fputc_unlocked not found)
Expected: true
/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp:541: Failure
Value of: isLibFunc(F, LF)
  Actual: false (fputs_unlocked not found)
Expected: true
/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp:541: Failure
Value of: isLibFunc(F, LF)
  Actual: false (fread_unlocked not found)
Expected: true
/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp:541: Failure
Value of: isLibFunc(F, LF)
  Actual: false (fwrite_unlocked not found)
Expected: true
/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp:541: Failure
Value of: isLibFunc(F, LF)
  Actual: false (getchar_unlocked not found)
Expected: true
/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp:541: Failure
Value of: isLibFunc(F, LF)
  Actual: false (putc_unlocked not found)
Expected: true
/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp:541: Failure
Value of: isLibFunc(F, LF)
  Actual: false (putchar_unlocked not found)
Expected: true
[  FAILED  ] TargetLibraryInfoTest.ValidProto (4 ms)
[----------] 1 test from TargetLibraryInfoTest (4 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (4 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] TargetLibraryInfoTest.ValidProto

 1 FAILED TEST

********************</pre><div class=""><br class=""></div></div><div class=""><br class=""></div><div class="">...</div><div><br class=""><blockquote type="cite" class=""><div class="">On Apr 26, 2018, at 3:31 PM, David Bolvansky via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Author: xbolva00<br class="">Date: Thu Apr 26 15:31:43 2018<br class="">New Revision: 331002<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=331002&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=331002&view=rev</a><br class="">Log:<br class="">[SimplifyLibcalls] Replace locked IO with unlocked IO<br class=""><br class="">Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,<br class=""><br class="">Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer<br class=""><br class="">Subscribers: lebedev.ri, llvm-commits<br class=""><br class="">Differential Revision: <a href="https://reviews.llvm.org/D45736" class="">https://reviews.llvm.org/D45736</a><br class=""><br class="">Added:<br class="">    llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll<br class="">Modified:<br class="">    llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def<br class="">    llvm/trunk/include/llvm/Transforms/Utils/BuildLibCalls.h<br class="">    llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h<br class="">    llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp<br class="">    llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp<br class="">    llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp<br class=""><br class="">Modified: llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def?rev=331002&r1=331001&r2=331002&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def?rev=331002&r1=331001&r2=331002&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def (original)<br class="">+++ llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def Thu Apr 26 15:31:43 2018<br class="">@@ -637,12 +637,18 @@ TLI_DEFINE_STRING_INTERNAL("ffsll")<br class=""> /// int fgetc(FILE *stream);<br class=""> TLI_DEFINE_ENUM_INTERNAL(fgetc)<br class=""> TLI_DEFINE_STRING_INTERNAL("fgetc")<br class="">+/// int fgetc_unlocked(FILE *stream);<br class="">+TLI_DEFINE_ENUM_INTERNAL(fgetc_unlocked)<br class="">+TLI_DEFINE_STRING_INTERNAL("fgetc_unlocked")<br class=""> /// int fgetpos(FILE *stream, fpos_t *pos);<br class=""> TLI_DEFINE_ENUM_INTERNAL(fgetpos)<br class=""> TLI_DEFINE_STRING_INTERNAL("fgetpos")<br class=""> /// char *fgets(char *s, int n, FILE *stream);<br class=""> TLI_DEFINE_ENUM_INTERNAL(fgets)<br class=""> TLI_DEFINE_STRING_INTERNAL("fgets")<br class="">+/// char *fgets_unlocked(char *s, int n, FILE *stream);<br class="">+TLI_DEFINE_ENUM_INTERNAL(fgets_unlocked)<br class="">+TLI_DEFINE_STRING_INTERNAL("fgets_unlocked")<br class=""> /// int fileno(FILE *stream);<br class=""> TLI_DEFINE_ENUM_INTERNAL(fileno)<br class=""> TLI_DEFINE_STRING_INTERNAL("fileno")<br class="">@@ -709,12 +715,21 @@ TLI_DEFINE_STRING_INTERNAL("fprintf")<br class=""> /// int fputc(int c, FILE *stream);<br class=""> TLI_DEFINE_ENUM_INTERNAL(fputc)<br class=""> TLI_DEFINE_STRING_INTERNAL("fputc")<br class="">+/// int fputc_unlocked(int c, FILE *stream);<br class="">+TLI_DEFINE_ENUM_INTERNAL(fputc_unlocked)<br class="">+TLI_DEFINE_STRING_INTERNAL("fputc_unlocked")<br class=""> /// int fputs(const char *s, FILE *stream);<br class=""> TLI_DEFINE_ENUM_INTERNAL(fputs)<br class=""> TLI_DEFINE_STRING_INTERNAL("fputs")<br class="">+/// int fputs_unlocked(const char *s, FILE *stream);<br class="">+TLI_DEFINE_ENUM_INTERNAL(fputs_unlocked)<br class="">+TLI_DEFINE_STRING_INTERNAL("fputs_unlocked")<br class=""> /// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);<br class=""> TLI_DEFINE_ENUM_INTERNAL(fread)<br class=""> TLI_DEFINE_STRING_INTERNAL("fread")<br class="">+/// size_t fread_unlocked(void *ptr, size_t size, size_t nitems, FILE *stream);<br class="">+TLI_DEFINE_ENUM_INTERNAL(fread_unlocked)<br class="">+TLI_DEFINE_STRING_INTERNAL("fread_unlocked")<br class=""> /// void free(void *ptr);<br class=""> TLI_DEFINE_ENUM_INTERNAL(free)<br class=""> TLI_DEFINE_STRING_INTERNAL("free")<br class="">@@ -772,6 +787,9 @@ TLI_DEFINE_STRING_INTERNAL("funlockfile"<br class=""> /// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);<br class=""> TLI_DEFINE_ENUM_INTERNAL(fwrite)<br class=""> TLI_DEFINE_STRING_INTERNAL("fwrite")<br class="">+/// size_t fwrite_unlocked(const void *ptr, size_t size, size_t nitems, FILE *stream);<br class="">+TLI_DEFINE_ENUM_INTERNAL(fwrite_unlocked)<br class="">+TLI_DEFINE_STRING_INTERNAL("fwrite_unlocked")<br class=""> /// int getc(FILE *stream);<br class=""> TLI_DEFINE_ENUM_INTERNAL(getc)<br class=""> TLI_DEFINE_STRING_INTERNAL("getc")<br class="">@@ -781,6 +799,9 @@ TLI_DEFINE_STRING_INTERNAL("getc_unlocke<br class=""> /// int getchar(void);<br class=""> TLI_DEFINE_ENUM_INTERNAL(getchar)<br class=""> TLI_DEFINE_STRING_INTERNAL("getchar")<br class="">+/// int getchar_unlocked(void);<br class="">+TLI_DEFINE_ENUM_INTERNAL(getchar_unlocked)<br class="">+TLI_DEFINE_STRING_INTERNAL("getchar_unlocked")<br class=""> /// char *getenv(const char *name);<br class=""> TLI_DEFINE_ENUM_INTERNAL(getenv)<br class=""> TLI_DEFINE_STRING_INTERNAL("getenv")<br class="">@@ -986,9 +1007,15 @@ TLI_DEFINE_STRING_INTERNAL("printf")<br class=""> /// int putc(int c, FILE *stream);<br class=""> TLI_DEFINE_ENUM_INTERNAL(putc)<br class=""> TLI_DEFINE_STRING_INTERNAL("putc")<br class="">+/// int putc_unlocked(int c, FILE *stream);<br class="">+TLI_DEFINE_ENUM_INTERNAL(putc_unlocked)<br class="">+TLI_DEFINE_STRING_INTERNAL("putc_unlocked")<br class=""> /// int putchar(int c);<br class=""> TLI_DEFINE_ENUM_INTERNAL(putchar)<br class=""> TLI_DEFINE_STRING_INTERNAL("putchar")<br class="">+/// int putchar_unlocked(int c);<br class="">+TLI_DEFINE_ENUM_INTERNAL(putchar_unlocked)<br class="">+TLI_DEFINE_STRING_INTERNAL("putchar_unlocked")<br class=""> /// int puts(const char *s);<br class=""> TLI_DEFINE_ENUM_INTERNAL(puts)<br class=""> TLI_DEFINE_STRING_INTERNAL("puts")<br class=""><br class="">Modified: llvm/trunk/include/llvm/Transforms/Utils/BuildLibCalls.h<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/BuildLibCalls.h?rev=331002&r1=331001&r2=331002&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/BuildLibCalls.h?rev=331002&r1=331001&r2=331002&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/Transforms/Utils/BuildLibCalls.h (original)<br class="">+++ llvm/trunk/include/llvm/Transforms/Utils/BuildLibCalls.h Thu Apr 26 15:31:43 2018<br class="">@@ -111,11 +111,21 @@ namespace llvm {<br class="">   Value *emitFPutC(Value *Char, Value *File, IRBuilder<> &B,<br class="">                    const TargetLibraryInfo *TLI);<br class=""><br class="">-  /// Emit a call to the puts function. Str is required to be a pointer and<br class="">+  /// Emit a call to the fputc_unlocked function. This assumes that Char is an<br class="">+  /// i32, and File is a pointer to FILE.<br class="">+  Value *emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B,<br class="">+                           const TargetLibraryInfo *TLI);<br class="">+<br class="">+  /// Emit a call to the fputs function. Str is required to be a pointer and<br class="">   /// File is a pointer to FILE.<br class="">   Value *emitFPutS(Value *Str, Value *File, IRBuilder<> &B,<br class="">                    const TargetLibraryInfo *TLI);<br class=""><br class="">+  /// Emit a call to the fputs_unlocked function. Str is required to be a<br class="">+  /// pointer and File is a pointer to FILE.<br class="">+  Value *emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B,<br class="">+                           const TargetLibraryInfo *TLI);<br class="">+<br class="">   /// Emit a call to the fwrite function. This assumes that Ptr is a pointer,<br class="">   /// Size is an 'intptr_t', and File is a pointer to FILE.<br class="">   Value *emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,<br class="">@@ -128,6 +138,27 @@ namespace llvm {<br class="">   /// Emit a call to the calloc function.<br class="">   Value *emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs,<br class="">                     IRBuilder<> &B, const TargetLibraryInfo &TLI);<br class="">+<br class="">+  /// Emit a call to the fwrite_unlocked function. This assumes that Ptr is a<br class="">+  /// pointer, Size is an 'intptr_t', N is nmemb and File is a pointer to FILE.<br class="">+  Value *emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,<br class="">+                            IRBuilder<> &B, const DataLayout &DL,<br class="">+                            const TargetLibraryInfo *TLI);<br class="">+<br class="">+  /// Emit a call to the fgetc_unlocked function. File is a pointer to FILE.<br class="">+  Value *emitFGetCUnlocked(Value *File, IRBuilder<> &B,<br class="">+                           const TargetLibraryInfo *TLI);<br class="">+<br class="">+  /// Emit a call to the fgets_unlocked function. Str is required to be a<br class="">+  /// pointer, Size is an i32 and File is a pointer to FILE.<br class="">+  Value *emitFGetSUnlocked(Value *Str, Value *Size, Value *File, IRBuilder<> &B,<br class="">+                           const TargetLibraryInfo *TLI);<br class="">+<br class="">+  /// Emit a call to the fread_unlocked function. This assumes that Ptr is a<br class="">+  /// pointer, Size is an 'intptr_t', N is nmemb and File is a pointer to FILE.<br class="">+  Value *emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,<br class="">+                           IRBuilder<> &B, const DataLayout &DL,<br class="">+                           const TargetLibraryInfo *TLI);<br class=""> }<br class=""><br class=""> #endif<br class=""><br class="">Modified: llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h?rev=331002&r1=331001&r2=331002&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h?rev=331002&r1=331001&r2=331002&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h (original)<br class="">+++ llvm/trunk/include/llvm/Transforms/Utils/SimplifyLibCalls.h Thu Apr 26 15:31:43 2018<br class="">@@ -161,7 +161,11 @@ private:<br class="">   Value *optimizeSPrintF(CallInst *CI, IRBuilder<> &B);<br class="">   Value *optimizeFPrintF(CallInst *CI, IRBuilder<> &B);<br class="">   Value *optimizeFWrite(CallInst *CI, IRBuilder<> &B);<br class="">+  Value *optimizeFRead(CallInst *CI, IRBuilder<> &B);<br class="">   Value *optimizeFPuts(CallInst *CI, IRBuilder<> &B);<br class="">+  Value *optimizeFGets(CallInst *CI, IRBuilder<> &B);<br class="">+  Value *optimizeFPutc(CallInst *CI, IRBuilder<> &B);<br class="">+  Value *optimizeFGetc(CallInst *CI, IRBuilder<> &B);<br class="">   Value *optimizePuts(CallInst *CI, IRBuilder<> &B);<br class=""><br class="">   // Helper methods<br class=""><br class="">Modified: llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp?rev=331002&r1=331001&r2=331002&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp?rev=331002&r1=331001&r2=331002&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp (original)<br class="">+++ llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp Thu Apr 26 15:31:43 2018<br class="">@@ -62,6 +62,18 @@ static void initialize(TargetLibraryInfo<br class="">                         }) &&<br class="">          "TargetLibraryInfoImpl function names must be sorted");<br class=""><br class="">+  // Set IO unlocked variants as unavailable<br class="">+  // Set them as available per system below<br class="">+  TLI.setUnavailable(LibFunc_getchar_unlocked);<br class="">+  TLI.setUnavailable(LibFunc_putc_unlocked);<br class="">+  TLI.setUnavailable(LibFunc_putchar_unlocked);<br class="">+  TLI.setUnavailable(LibFunc_fputc_unlocked);<br class="">+  TLI.setUnavailable(LibFunc_fgetc_unlocked);<br class="">+  TLI.setUnavailable(LibFunc_fread_unlocked);<br class="">+  TLI.setUnavailable(LibFunc_fwrite_unlocked);<br class="">+  TLI.setUnavailable(LibFunc_fputs_unlocked);<br class="">+  TLI.setUnavailable(LibFunc_fgets_unlocked);<br class="">+<br class="">   bool ShouldExtI32Param = false, ShouldExtI32Return = false,<br class="">        ShouldSignExtI32Param = false;<br class="">   // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and<br class="">@@ -107,6 +119,12 @@ static void initialize(TargetLibraryInfo<br class="">   // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.<br class="">   // All versions of watchOS support it.<br class="">   if (T.isMacOSX()) {<br class="">+    // available IO unlocked variants on Mac OS X<br class="">+    TLI.setAvailable(LibFunc_getc_unlocked);<br class="">+    TLI.setAvailable(LibFunc_getchar_unlocked);<br class="">+    TLI.setAvailable(LibFunc_putc_unlocked);<br class="">+    TLI.setAvailable(LibFunc_putchar_unlocked);<br class="">+<br class="">     if (T.isMacOSXVersionLT(10, 5))<br class="">       TLI.setUnavailable(LibFunc_memset_pattern16);<br class="">   } else if (T.isiOS()) {<br class="">@@ -265,7 +283,6 @@ static void initialize(TargetLibraryInfo<br class="">     TLI.setUnavailable(LibFunc_ftello);<br class="">     TLI.setUnavailable(LibFunc_ftrylockfile);<br class="">     TLI.setUnavailable(LibFunc_funlockfile);<br class="">-    TLI.setUnavailable(LibFunc_getc_unlocked);<br class="">     TLI.setUnavailable(LibFunc_getitimer);<br class="">     TLI.setUnavailable(LibFunc_getlogin_r);<br class="">     TLI.setUnavailable(LibFunc_getpwnam);<br class="">@@ -465,6 +482,20 @@ static void initialize(TargetLibraryInfo<br class="">     TLI.setUnavailable(LibFunc_sinhl_finite);<br class="">   }<br class=""><br class="">+  if (T.isOSLinux()) {<br class="">+    // available IO unlocked variants on Linux<br class="">+    TLI.setAvailable(LibFunc_getc_unlocked);<br class="">+    TLI.setAvailable(LibFunc_getchar_unlocked);<br class="">+    TLI.setAvailable(LibFunc_putc_unlocked);<br class="">+    TLI.setAvailable(LibFunc_putchar_unlocked);<br class="">+    TLI.setAvailable(LibFunc_fputc_unlocked);<br class="">+    TLI.setAvailable(LibFunc_fgetc_unlocked);<br class="">+    TLI.setAvailable(LibFunc_fread_unlocked);<br class="">+    TLI.setAvailable(LibFunc_fwrite_unlocked);<br class="">+    TLI.setAvailable(LibFunc_fputs_unlocked);<br class="">+    TLI.setAvailable(LibFunc_fgets_unlocked);<br class="">+  }<br class="">+<br class="">   // As currently implemented in clang, NVPTX code has no standard library to<br class="">   // speak of.  Headers provide a standard-ish library implementation, but many<br class="">   // of the signatures are wrong -- for example, many libm functions are not<br class="">@@ -805,6 +836,7 @@ bool TargetLibraryInfoImpl::isValidProto<br class="">   case LibFunc_feof:<br class="">   case LibFunc_fflush:<br class="">   case LibFunc_fgetc:<br class="">+  case LibFunc_fgetc_unlocked:<br class="">   case LibFunc_fileno:<br class="">   case LibFunc_flockfile:<br class="">   case LibFunc_free:<br class="">@@ -833,6 +865,7 @@ bool TargetLibraryInfoImpl::isValidProto<br class="">     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&<br class="">             FTy.getParamType(1)->isPointerTy());<br class="">   case LibFunc_fputc:<br class="">+  case LibFunc_fputc_unlocked:<br class="">   case LibFunc_fstat:<br class="">   case LibFunc_frexp:<br class="">   case LibFunc_frexpf:<br class="">@@ -840,18 +873,22 @@ bool TargetLibraryInfoImpl::isValidProto<br class="">   case LibFunc_fstatvfs:<br class="">     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());<br class="">   case LibFunc_fgets:<br class="">+  case LibFunc_fgets_unlocked:<br class="">     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&<br class="">             FTy.getParamType(2)->isPointerTy());<br class="">   case LibFunc_fread:<br class="">+  case LibFunc_fread_unlocked:<br class="">     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&<br class="">             FTy.getParamType(3)->isPointerTy());<br class="">   case LibFunc_fwrite:<br class="">+  case LibFunc_fwrite_unlocked:<br class="">     return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&<br class="">             FTy.getParamType(0)->isPointerTy() &&<br class="">             FTy.getParamType(1)->isIntegerTy() &&<br class="">             FTy.getParamType(2)->isIntegerTy() &&<br class="">             FTy.getParamType(3)->isPointerTy());<br class="">   case LibFunc_fputs:<br class="">+  case LibFunc_fputs_unlocked:<br class="">     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&<br class="">             FTy.getParamType(1)->isPointerTy());<br class="">   case LibFunc_fscanf:<br class="">@@ -864,6 +901,7 @@ bool TargetLibraryInfoImpl::isValidProto<br class="">     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&<br class="">             FTy.getParamType(1)->isPointerTy());<br class="">   case LibFunc_getchar:<br class="">+  case LibFunc_getchar_unlocked:<br class="">     return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());<br class="">   case LibFunc_gets:<br class="">     return (NumParams == 1 && FTy.getParamType(0) == PCharTy);<br class="">@@ -876,6 +914,7 @@ bool TargetLibraryInfoImpl::isValidProto<br class="">     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&<br class="">             FTy.getParamType(1)->isPointerTy());<br class="">   case LibFunc_putc:<br class="">+  case LibFunc_putc_unlocked:<br class="">     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());<br class="">   case LibFunc_pread:<br class="">   case LibFunc_pwrite:<br class="">@@ -1262,6 +1301,7 @@ bool TargetLibraryInfoImpl::isValidProto<br class="">   case LibFunc_isascii:<br class="">   case LibFunc_toascii:<br class="">   case LibFunc_putchar:<br class="">+  case LibFunc_putchar_unlocked:<br class="">     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&<br class="">             FTy.getReturnType() == FTy.getParamType(0));<br class=""><br class=""><br class="">Modified: llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp?rev=331002&r1=331001&r2=331002&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp?rev=331002&r1=331001&r2=331002&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp (original)<br class="">+++ llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp Thu Apr 26 15:31:43 2018<br class="">@@ -386,6 +386,7 @@ bool llvm::inferLibFuncAttributes(Functi<br class="">   case LibFunc_fseek:<br class="">   case LibFunc_ftell:<br class="">   case LibFunc_fgetc:<br class="">+  case LibFunc_fgetc_unlocked:<br class="">   case LibFunc_fseeko:<br class="">   case LibFunc_ftello:<br class="">   case LibFunc_fileno:<br class="">@@ -404,6 +405,7 @@ bool llvm::inferLibFuncAttributes(Functi<br class="">     Changed |= setOnlyReadsMemory(F);<br class="">     return Changed;<br class="">   case LibFunc_fputc:<br class="">+  case LibFunc_fputc_unlocked:<br class="">   case LibFunc_fstat:<br class="">   case LibFunc_frexp:<br class="">   case LibFunc_frexpf:<br class="">@@ -413,21 +415,25 @@ bool llvm::inferLibFuncAttributes(Functi<br class="">     Changed |= setDoesNotCapture(F, 1);<br class="">     return Changed;<br class="">   case LibFunc_fgets:<br class="">+  case LibFunc_fgets_unlocked:<br class="">     Changed |= setDoesNotThrow(F);<br class="">     Changed |= setDoesNotCapture(F, 2);<br class="">     return Changed;<br class="">   case LibFunc_fread:<br class="">+  case LibFunc_fread_unlocked:<br class="">     Changed |= setDoesNotThrow(F);<br class="">     Changed |= setDoesNotCapture(F, 0);<br class="">     Changed |= setDoesNotCapture(F, 3);<br class="">     return Changed;<br class="">   case LibFunc_fwrite:<br class="">+  case LibFunc_fwrite_unlocked:<br class="">     Changed |= setDoesNotThrow(F);<br class="">     Changed |= setDoesNotCapture(F, 0);<br class="">     Changed |= setDoesNotCapture(F, 3);<br class="">     // FIXME: readonly #1?<br class="">     return Changed;<br class="">   case LibFunc_fputs:<br class="">+  case LibFunc_fputs_unlocked:<br class="">     Changed |= setDoesNotThrow(F);<br class="">     Changed |= setDoesNotCapture(F, 0);<br class="">     Changed |= setDoesNotCapture(F, 1);<br class="">@@ -458,6 +464,7 @@ bool llvm::inferLibFuncAttributes(Functi<br class="">     return Changed;<br class="">   case LibFunc_gets:<br class="">   case LibFunc_getchar:<br class="">+  case LibFunc_getchar_unlocked:<br class="">     Changed |= setDoesNotThrow(F);<br class="">     return Changed;<br class="">   case LibFunc_getitimer:<br class="">@@ -496,6 +503,7 @@ bool llvm::inferLibFuncAttributes(Functi<br class="">     Changed |= setOnlyReadsMemory(F, 1);<br class="">     return Changed;<br class="">   case LibFunc_putc:<br class="">+  case LibFunc_putc_unlocked:<br class="">     Changed |= setDoesNotThrow(F);<br class="">     Changed |= setDoesNotCapture(F, 1);<br class="">     return Changed;<br class="">@@ -516,6 +524,7 @@ bool llvm::inferLibFuncAttributes(Functi<br class="">     Changed |= setOnlyReadsMemory(F, 1);<br class="">     return Changed;<br class="">   case LibFunc_putchar:<br class="">+  case LibFunc_putchar_unlocked:<br class="">     Changed |= setDoesNotThrow(F);<br class="">     return Changed;<br class="">   case LibFunc_popen:<br class="">@@ -997,6 +1006,24 @@ Value *llvm::emitFPutC(Value *Char, Valu<br class="">   return CI;<br class=""> }<br class=""><br class="">+Value *llvm::emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B,<br class="">+                               const TargetLibraryInfo *TLI) {<br class="">+  if (!TLI->has(LibFunc_fputc_unlocked))<br class="">+    return nullptr;<br class="">+<br class="">+  Module *M = B.GetInsertBlock()->getModule();<br class="">+  Constant *F = M->getOrInsertFunction("fputc_unlocked", B.getInt32Ty(),<br class="">+                                       B.getInt32Ty(), File->getType());<br class="">+  if (File->getType()->isPointerTy())<br class="">+    inferLibFuncAttributes(*M->getFunction("fputc_unlocked"), *TLI);<br class="">+  Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/ true, "chari");<br class="">+  CallInst *CI = B.CreateCall(F, {Char, File}, "fputc_unlocked");<br class="">+<br class="">+  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))<br class="">+    CI->setCallingConv(Fn->getCallingConv());<br class="">+  return CI;<br class="">+}<br class="">+<br class=""> Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilder<> &B,<br class="">                        const TargetLibraryInfo *TLI) {<br class="">   if (!TLI->has(LibFunc_fputs))<br class="">@@ -1015,6 +1042,24 @@ Value *llvm::emitFPutS(Value *Str, Value<br class="">   return CI;<br class=""> }<br class=""><br class="">+Value *llvm::emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B,<br class="">+                               const TargetLibraryInfo *TLI) {<br class="">+  if (!TLI->has(LibFunc_fputs_unlocked))<br class="">+    return nullptr;<br class="">+<br class="">+  Module *M = B.GetInsertBlock()->getModule();<br class="">+  StringRef FPutsUnlockedName = TLI->getName(LibFunc_fputs_unlocked);<br class="">+  Constant *F = M->getOrInsertFunction(FPutsUnlockedName, B.getInt32Ty(),<br class="">+                                       B.getInt8PtrTy(), File->getType());<br class="">+  if (File->getType()->isPointerTy())<br class="">+    inferLibFuncAttributes(*M->getFunction(FPutsUnlockedName), *TLI);<br class="">+  CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs_unlocked");<br class="">+<br class="">+  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))<br class="">+    CI->setCallingConv(Fn->getCallingConv());<br class="">+  return CI;<br class="">+}<br class="">+<br class=""> Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,<br class="">                         const DataLayout &DL, const TargetLibraryInfo *TLI) {<br class="">   if (!TLI->has(LibFunc_fwrite))<br class="">@@ -1074,3 +1119,82 @@ Value *llvm::emitCalloc(Value *Num, Valu<br class=""><br class="">   return CI;<br class=""> }<br class="">+<br class="">+Value *llvm::emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,<br class="">+                                IRBuilder<> &B, const DataLayout &DL,<br class="">+                                const TargetLibraryInfo *TLI) {<br class="">+  if (!TLI->has(LibFunc_fwrite_unlocked))<br class="">+    return nullptr;<br class="">+<br class="">+  Module *M = B.GetInsertBlock()->getModule();<br class="">+  LLVMContext &Context = B.GetInsertBlock()->getContext();<br class="">+  StringRef FWriteUnlockedName = TLI->getName(LibFunc_fwrite_unlocked);<br class="">+  Constant *F = M->getOrInsertFunction(<br class="">+      FWriteUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(),<br class="">+      DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());<br class="">+<br class="">+  if (File->getType()->isPointerTy())<br class="">+    inferLibFuncAttributes(*M->getFunction(FWriteUnlockedName), *TLI);<br class="">+  CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File});<br class="">+<br class="">+  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))<br class="">+    CI->setCallingConv(Fn->getCallingConv());<br class="">+  return CI;<br class="">+}<br class="">+<br class="">+Value *llvm::emitFGetCUnlocked(Value *File, IRBuilder<> &B,<br class="">+                               const TargetLibraryInfo *TLI) {<br class="">+  if (!TLI->has(LibFunc_fgetc_unlocked))<br class="">+    return nullptr;<br class="">+<br class="">+  Module *M = B.GetInsertBlock()->getModule();<br class="">+  Constant *F =<br class="">+      M->getOrInsertFunction("fgetc_unlocked", B.getInt32Ty(), File->getType());<br class="">+  if (File->getType()->isPointerTy())<br class="">+    inferLibFuncAttributes(*M->getFunction("fgetc_unlocked"), *TLI);<br class="">+  CallInst *CI = B.CreateCall(F, File, "fgetc_unlocked");<br class="">+<br class="">+  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))<br class="">+    CI->setCallingConv(Fn->getCallingConv());<br class="">+  return CI;<br class="">+}<br class="">+<br class="">+Value *llvm::emitFGetSUnlocked(Value *Str, Value *Size, Value *File,<br class="">+                               IRBuilder<> &B, const TargetLibraryInfo *TLI) {<br class="">+  if (!TLI->has(LibFunc_fgets_unlocked))<br class="">+    return nullptr;<br class="">+<br class="">+  Module *M = B.GetInsertBlock()->getModule();<br class="">+  Constant *F =<br class="">+      M->getOrInsertFunction("fgets_unlocked", B.getInt32Ty(), B.getInt8PtrTy(),<br class="">+                             B.getInt32Ty(), File->getType());<br class="">+  inferLibFuncAttributes(*M->getFunction("fgets_unlocked"), *TLI);<br class="">+  CallInst *CI =<br class="">+      B.CreateCall(F, {castToCStr(Str, B), Size, File}, "fgets_unlocked");<br class="">+<br class="">+  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))<br class="">+    CI->setCallingConv(Fn->getCallingConv());<br class="">+  return CI;<br class="">+}<br class="">+<br class="">+Value *llvm::emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,<br class="">+                               IRBuilder<> &B, const DataLayout &DL,<br class="">+                               const TargetLibraryInfo *TLI) {<br class="">+  if (!TLI->has(LibFunc_fread_unlocked))<br class="">+    return nullptr;<br class="">+<br class="">+  Module *M = B.GetInsertBlock()->getModule();<br class="">+  LLVMContext &Context = B.GetInsertBlock()->getContext();<br class="">+  StringRef FReadUnlockedName = TLI->getName(LibFunc_fread_unlocked);<br class="">+  Constant *F = M->getOrInsertFunction(<br class="">+      FReadUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(),<br class="">+      DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());<br class="">+<br class="">+  if (File->getType()->isPointerTy())<br class="">+    inferLibFuncAttributes(*M->getFunction(FReadUnlockedName), *TLI);<br class="">+  CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File});<br class="">+<br class="">+  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))<br class="">+    CI->setCallingConv(Fn->getCallingConv());<br class="">+  return CI;<br class="">+}<br class=""><br class="">Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=331002&r1=331001&r2=331002&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=331002&r1=331001&r2=331002&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)<br class="">+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Thu Apr 26 15:31:43 2018<br class="">@@ -21,6 +21,7 @@<br class=""> #include "llvm/Analysis/TargetLibraryInfo.h"<br class=""> #include "llvm/Analysis/Utils/Local.h"<br class=""> #include "llvm/Analysis/ValueTracking.h"<br class="">+#include "llvm/Analysis/CaptureTracking.h"<br class=""> #include "llvm/IR/DataLayout.h"<br class=""> #include "llvm/IR/Function.h"<br class=""> #include "llvm/IR/IRBuilder.h"<br class="">@@ -127,6 +128,28 @@ static Value *convertStrToNumber(CallIns<br class="">   return ConstantInt::get(CI->getType(), Result);<br class=""> }<br class=""><br class="">+static bool isLocallyOpenedFile(Value *File, CallInst *CI, IRBuilder<> &B,<br class="">+                                const TargetLibraryInfo *TLI) {<br class="">+  CallInst *FOpen = dyn_cast<CallInst>(File);<br class="">+  if (!FOpen)<br class="">+    return false;<br class="">+<br class="">+  Function *InnerCallee = FOpen->getCalledFunction();<br class="">+  if (!InnerCallee)<br class="">+    return false;<br class="">+<br class="">+  LibFunc Func;<br class="">+  if (!TLI->getLibFunc(*InnerCallee, Func) || !TLI->has(Func) ||<br class="">+      Func != LibFunc_fopen)<br class="">+    return false;<br class="">+<br class="">+  inferLibFuncAttributes(*CI->getCalledFunction(), *TLI);<br class="">+  if (PointerMayBeCaptured(File, true, true))<br class="">+    return false;<br class="">+<br class="">+  return true;<br class="">+}<br class="">+<br class=""> //===----------------------------------------------------------------------===//<br class=""> // String and Memory Library Call Optimizations<br class=""> //===----------------------------------------------------------------------===//<br class="">@@ -1988,22 +2011,27 @@ Value *LibCallSimplifier::optimizeFWrite<br class="">   // Get the element size and count.<br class="">   ConstantInt *SizeC = dyn_cast<ConstantInt>(CI->getArgOperand(1));<br class="">   ConstantInt *CountC = dyn_cast<ConstantInt>(CI->getArgOperand(2));<br class="">-  if (!SizeC || !CountC)<br class="">-    return nullptr;<br class="">-  uint64_t Bytes = SizeC->getZExtValue() * CountC->getZExtValue();<br class="">-<br class="">-  // If this is writing zero records, remove the call (it's a noop).<br class="">-  if (Bytes == 0)<br class="">-    return ConstantInt::get(CI->getType(), 0);<br class="">+  if (SizeC && CountC) {<br class="">+    uint64_t Bytes = SizeC->getZExtValue() * CountC->getZExtValue();<br class=""><br class="">-  // If this is writing one byte, turn it into fputc.<br class="">-  // This optimisation is only valid, if the return value is unused.<br class="">-  if (Bytes == 1 && CI->use_empty()) { // fwrite(S,1,1,F) -> fputc(S[0],F)<br class="">-    Value *Char = B.CreateLoad(castToCStr(CI->getArgOperand(0), B), "char");<br class="">-    Value *NewCI = emitFPutC(Char, CI->getArgOperand(3), B, TLI);<br class="">-    return NewCI ? ConstantInt::get(CI->getType(), 1) : nullptr;<br class="">+    // If this is writing zero records, remove the call (it's a noop).<br class="">+    if (Bytes == 0)<br class="">+      return ConstantInt::get(CI->getType(), 0);<br class="">+<br class="">+    // If this is writing one byte, turn it into fputc.<br class="">+    // This optimisation is only valid, if the return value is unused.<br class="">+    if (Bytes == 1 && CI->use_empty()) { // fwrite(S,1,1,F) -> fputc(S[0],F)<br class="">+      Value *Char = B.CreateLoad(castToCStr(CI->getArgOperand(0), B), "char");<br class="">+      Value *NewCI = emitFPutC(Char, CI->getArgOperand(3), B, TLI);<br class="">+      return NewCI ? ConstantInt::get(CI->getType(), 1) : nullptr;<br class="">+    }<br class="">   }<br class=""><br class="">+  if (isLocallyOpenedFile(CI->getArgOperand(3), CI, B, TLI))<br class="">+    return emitFWriteUnlocked(CI->getArgOperand(0), CI->getArgOperand(1),<br class="">+                              CI->getArgOperand(2), CI->getArgOperand(3), B, DL,<br class="">+                              TLI);<br class="">+<br class="">   return nullptr;<br class=""> }<br class=""><br class="">@@ -2015,9 +2043,14 @@ Value *LibCallSimplifier::optimizeFPuts(<br class="">   if (CI->getParent()->getParent()->optForSize())<br class="">     return nullptr;<br class=""><br class="">-  // We can't optimize if return value is used.<br class="">-  if (!CI->use_empty())<br class="">-    return nullptr;<br class="">+  if (CI->use_empty()) {<br class="">+    if (isLocallyOpenedFile(CI->getArgOperand(1), CI, B, TLI))<br class="">+      return emitFPutSUnlocked(CI->getArgOperand(0), CI->getArgOperand(1), B,<br class="">+                               TLI);<br class="">+    else<br class="">+      // We can't optimize if return value is used.<br class="">+      return nullptr;<br class="">+  }<br class=""><br class="">   // fputs(s,F) --> fwrite(s,1,strlen(s),F)<br class="">   uint64_t Len = GetStringLength(CI->getArgOperand(0));<br class="">@@ -2031,6 +2064,40 @@ Value *LibCallSimplifier::optimizeFPuts(<br class="">       CI->getArgOperand(1), B, DL, TLI);<br class=""> }<br class=""><br class="">+Value *LibCallSimplifier::optimizeFPutc(CallInst *CI, IRBuilder<> &B) {<br class="">+  optimizeErrorReporting(CI, B, 1);<br class="">+<br class="">+  if (isLocallyOpenedFile(CI->getArgOperand(1), CI, B, TLI))<br class="">+    return emitFPutCUnlocked(CI->getArgOperand(0), CI->getArgOperand(1), B,<br class="">+                             TLI);<br class="">+<br class="">+  return nullptr;<br class="">+}<br class="">+<br class="">+Value *LibCallSimplifier::optimizeFGetc(CallInst *CI, IRBuilder<> &B) {<br class="">+  if (isLocallyOpenedFile(CI->getArgOperand(0), CI, B, TLI))<br class="">+    return emitFGetCUnlocked(CI->getArgOperand(0), B, TLI);<br class="">+<br class="">+  return nullptr;<br class="">+}<br class="">+<br class="">+Value *LibCallSimplifier::optimizeFGets(CallInst *CI, IRBuilder<> &B) {<br class="">+  if (isLocallyOpenedFile(CI->getArgOperand(2), CI, B, TLI))<br class="">+    return emitFGetSUnlocked(CI->getArgOperand(0), CI->getArgOperand(1),<br class="">+                             CI->getArgOperand(2), B, TLI);<br class="">+<br class="">+  return nullptr;<br class="">+}<br class="">+<br class="">+Value *LibCallSimplifier::optimizeFRead(CallInst *CI, IRBuilder<> &B) {<br class="">+  if (isLocallyOpenedFile(CI->getArgOperand(3), CI, B, TLI))<br class="">+    return emitFReadUnlocked(CI->getArgOperand(0), CI->getArgOperand(1),<br class="">+                             CI->getArgOperand(2), CI->getArgOperand(3), B, DL,<br class="">+                             TLI);<br class="">+<br class="">+  return nullptr;<br class="">+}<br class="">+<br class=""> Value *LibCallSimplifier::optimizePuts(CallInst *CI, IRBuilder<> &B) {<br class="">   // Check for a constant string.<br class="">   StringRef Str;<br class="">@@ -2322,8 +2389,16 @@ Value *LibCallSimplifier::optimizeCall(C<br class="">       return optimizeFPrintF(CI, Builder);<br class="">     case LibFunc_fwrite:<br class="">       return optimizeFWrite(CI, Builder);<br class="">+    case LibFunc_fread:<br class="">+      return optimizeFRead(CI, Builder);<br class="">     case LibFunc_fputs:<br class="">       return optimizeFPuts(CI, Builder);<br class="">+    case LibFunc_fgets:<br class="">+      return optimizeFGets(CI, Builder);<br class="">+    case LibFunc_fputc:<br class="">+      return optimizeFPutc(CI, Builder);<br class="">+    case LibFunc_fgetc:<br class="">+      return optimizeFGetc(CI, Builder);<br class="">     case LibFunc_puts:<br class="">       return optimizePuts(CI, Builder);<br class="">     case LibFunc_perror:<br class="">@@ -2331,8 +2406,6 @@ Value *LibCallSimplifier::optimizeCall(C<br class="">     case LibFunc_vfprintf:<br class="">     case LibFunc_fiprintf:<br class="">       return optimizeErrorReporting(CI, Builder, 0);<br class="">-    case LibFunc_fputc:<br class="">-      return optimizeErrorReporting(CI, Builder, 1);<br class="">     default:<br class="">       return nullptr;<br class="">     }<br class=""><br class="">Added: llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll?rev=331002&view=auto" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll?rev=331002&view=auto</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll (added)<br class="">+++ llvm/trunk/test/Transforms/InstCombine/unlocked-stdio.ll Thu Apr 26 15:31:43 2018<br class="">@@ -0,0 +1,145 @@<br class="">+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py<br class="">+; RUN: opt < %s -instcombine -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s<br class="">+<br class="">+%struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i64, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i64, i32, [20 x i8] }<br class="">+%struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 }<br class="">+<br class="">+@.str = private unnamed_addr constant [5 x i8] c"file\00", align 1<br class="">+@.str.1 = private unnamed_addr constant [2 x i8] c"w\00", align 1<br class="">+@.str.2 = private unnamed_addr constant [4 x i8] c"str\00", align 1<br class="">+<br class="">+define void @external_fgetc_test(%struct._IO_FILE* %f) {<br class="">+; CHECK-LABEL: @external_fgetc_test(<br class="">+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @fgetc(%struct._IO_FILE* [[F:%.*]])<br class="">+; CHECK-NEXT:    ret void<br class="">+;<br class="">+  %call = call i32 @fgetc(%struct._IO_FILE* %f)<br class="">+  ret void<br class="">+}<br class="">+<br class="">+declare i32 @fgetc(%struct._IO_FILE* nocapture) #0<br class="">+<br class="">+define void @external_fgetc_test2() {<br class="">+; CHECK-LABEL: @external_fgetc_test2(<br class="">+; CHECK-NEXT:    [[CALL:%.*]] = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+; CHECK-NEXT:    [[FPUTC_UNLOCKED:%.*]] = call i32 @fputc_unlocked(i32 99, %struct._IO_FILE* [[CALL]])<br class="">+; CHECK-NEXT:    ret void<br class="">+;<br class="">+  %call = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+  %call1 = call i32 @fputc(i32 99, %struct._IO_FILE* %call)<br class="">+  ret void<br class="">+}<br class="">+<br class="">+declare %struct._IO_FILE* @fopen(i8*, i8*)<br class="">+declare i32 @fputc(i32, %struct._IO_FILE* nocapture) #0<br class="">+<br class="">+define internal void @fgetc_test() {<br class="">+; CHECK-LABEL: @fgetc_test(<br class="">+; CHECK-NEXT:    [[CALL:%.*]] = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+; CHECK-NEXT:    [[FGETC_UNLOCKED:%.*]] = call i32 @fgetc_unlocked(%struct._IO_FILE* [[CALL]])<br class="">+; CHECK-NEXT:    ret void<br class="">+;<br class="">+  %call = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+  %call1 = call i32 @fgetc(%struct._IO_FILE* %call)<br class="">+  ret void<br class="">+}<br class="">+<br class="">+define void @external_fgetc_internal_test() {<br class="">+; CHECK-LABEL: @external_fgetc_internal_test(<br class="">+; CHECK-NEXT:    call void @fgetc_test()<br class="">+; CHECK-NEXT:    ret void<br class="">+;<br class="">+  call void @fgetc_test()<br class="">+  ret void<br class="">+}<br class="">+<br class="">+define internal void @fwrite_test() {<br class="">+; CHECK-LABEL: @fwrite_test(<br class="">+; CHECK-NEXT:    [[S:%.*]] = alloca [10 x i8], align 1<br class="">+; CHECK-NEXT:    [[CALL:%.*]] = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+; CHECK-NEXT:    [[ARRAYDECAY:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[S]], i64 0, i64 0<br class="">+; CHECK-NEXT:    [[TMP1:%.*]] = call i64 @fwrite_unlocked(i8* nonnull [[ARRAYDECAY]], i64 10, i64 10, %struct._IO_FILE* [[CALL]])<br class="">+; CHECK-NEXT:    ret void<br class="">+;<br class="">+  %s = alloca [10 x i8], align 1<br class="">+  %call = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+  %arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %s, i64 0, i64 0<br class="">+  %call1 = call i64 @fwrite(i8* nonnull %arraydecay, i64 10, i64 10, %struct._IO_FILE* %call)<br class="">+  ret void<br class="">+}<br class="">+<br class="">+define internal void @fread_test() {<br class="">+; CHECK-LABEL: @fread_test(<br class="">+; CHECK-NEXT:    [[S:%.*]] = alloca [10 x i8], align 1<br class="">+; CHECK-NEXT:    [[CALL:%.*]] = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+; CHECK-NEXT:    [[ARRAYDECAY:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[S]], i64 0, i64 0<br class="">+; CHECK-NEXT:    [[TMP1:%.*]] = call i64 @fread_unlocked(i8* nonnull [[ARRAYDECAY]], i64 10, i64 10, %struct._IO_FILE* [[CALL]])<br class="">+; CHECK-NEXT:    ret void<br class="">+;<br class="">+  %s = alloca [10 x i8], align 1<br class="">+  %call = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+  %arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %s, i64 0, i64 0<br class="">+  %call1 = call i64 @fread(i8* nonnull %arraydecay, i64 10, i64 10, %struct._IO_FILE* %call)<br class="">+  ret void<br class="">+}<br class="">+<br class="">+define internal void @fputs_test() {<br class="">+; CHECK-LABEL: @fputs_test(<br class="">+; CHECK-NEXT:    [[CALL:%.*]] = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+; CHECK-NEXT:    [[FPUTS_UNLOCKED:%.*]] = call i32 @fputs_unlocked(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %struct._IO_FILE* [[CALL]])<br class="">+; CHECK-NEXT:    ret void<br class="">+;<br class="">+  %call = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+  %call1 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %struct._IO_FILE* %call)<br class="">+  ret void<br class="">+}<br class="">+<br class="">+define internal void @fgets_test() {<br class="">+; CHECK-LABEL: @fgets_test(<br class="">+; CHECK-NEXT:    [[BUF:%.*]] = alloca [10 x i8], align 1<br class="">+; CHECK-NEXT:    [[CALL:%.*]] = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+; CHECK-NEXT:    [[ARRAYDECAY:%.*]] = getelementptr inbounds [10 x i8], [10 x i8]* [[BUF]], i64 0, i64 0<br class="">+; CHECK-NEXT:    [[FGETS_UNLOCKED:%.*]] = call i32 @fgets_unlocked(i8* nonnull [[ARRAYDECAY]], i32 10, %struct._IO_FILE* [[CALL]])<br class="">+; CHECK-NEXT:    ret void<br class="">+;<br class="">+  %buf = alloca [10 x i8], align 1<br class="">+  %call = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+  %arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %buf, i64 0, i64 0<br class="">+  %call1 = call i8* @fgets(i8* nonnull %arraydecay, i32 10, %struct._IO_FILE* %call)<br class="">+  ret void<br class="">+}<br class="">+<br class="">+define internal void @fputc_test() {<br class="">+; CHECK-LABEL: @fputc_test(<br class="">+; CHECK-NEXT:    [[CALL:%.*]] = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+; CHECK-NEXT:    [[FPUTC_UNLOCKED:%.*]] = call i32 @fputc_unlocked(i32 99, %struct._IO_FILE* [[CALL]])<br class="">+; CHECK-NEXT:    ret void<br class="">+;<br class="">+  %call = call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))<br class="">+  %call1 = call i32 @fputc(i32 99, %struct._IO_FILE* %call)<br class="">+  ret void<br class="">+}<br class="">+<br class="">+define i32 @main() {<br class="">+; CHECK-LABEL: @main(<br class="">+; CHECK-NEXT:    call void @fwrite_test()<br class="">+; CHECK-NEXT:    call void @fread_test()<br class="">+; CHECK-NEXT:    call void @fputs_test()<br class="">+; CHECK-NEXT:    call void @fgets_test()<br class="">+; CHECK-NEXT:    call void @fputc_test()<br class="">+; CHECK-NEXT:    call void @fgetc_test()<br class="">+; CHECK-NEXT:    ret i32 0<br class="">+;<br class="">+  call void @fwrite_test()<br class="">+  call void @fread_test()<br class="">+  call void @fputs_test()<br class="">+  call void @fgets_test()<br class="">+  call void @fputc_test()<br class="">+  call void @fgetc_test()<br class="">+  ret i32 0<br class="">+}<br class="">+<br class="">+declare i64 @fwrite(i8* nocapture, i64, i64, %struct._IO_FILE* nocapture) #0<br class="">+declare i64 @fread(i8* nocapture, i64, i64, %struct._IO_FILE* nocapture) #0<br class="">+declare i32 @fputs(i8* nocapture readonly, %struct._IO_FILE* nocapture) #0<br class="">+declare i8* @fgets(i8*, i32, %struct._IO_FILE* nocapture) #0<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></div></blockquote></div><br class=""></div></body></html>