[PATCH] D34043: [CGP] don't expand a memcmp with nobuiltin attribute

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 8 12:48:00 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL305007: [CGP] don't expand a memcmp with nobuiltin attribute (authored by spatel).

Changed prior to commit:
  https://reviews.llvm.org/D34043?vs=101949&id=101954#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34043

Files:
  llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
  llvm/trunk/test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll


Index: llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.h
===================================================================
--- llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.h
+++ llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.h
@@ -13,6 +13,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/IR/CallSite.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassManager.h"
@@ -239,6 +240,13 @@
     return Impl->getLibFunc(FDecl, F);
   }
 
+  /// If a callsite does not have the 'nobuiltin' attribute, return if the
+  /// called function is a known library function and set F to that function.
+  bool getLibFunc(ImmutableCallSite CS, LibFunc & F) const {
+    return !CS.isNoBuiltin() && CS.getCalledFunction() &&
+           getLibFunc(*(CS.getCalledFunction()), F);
+  }
+
   /// Tests whether a library function is available.
   bool has(LibFunc F) const {
     return Impl->getState(F) != TargetLibraryInfoImpl::Unavailable;
Index: llvm/trunk/test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll
===================================================================
--- llvm/trunk/test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll
+++ llvm/trunk/test/CodeGen/PowerPC/memCmpUsedInZeroEqualityComparison.ll
@@ -199,12 +199,21 @@
 define i1 @length2_eq_nobuiltin_attr(i8* %X, i8* %Y) {
 ; CHECK-LABEL: length2_eq_nobuiltin_attr:
 ; CHECK:       # BB#0:
-; CHECK-NEXT:    lhz 3, 0(3)
-; CHECK-NEXT:    lhz 4, 0(4)
-; CHECK-NEXT:    li 5, 0
-; CHECK-NEXT:    li 12, 1
-; CHECK-NEXT:    cmpw 3, 4
-; CHECK-NEXT:    isel 3, 12, 5, 2
+; CHECK-NEXT:    mflr 0
+; CHECK-NEXT:    std 0, 16(1)
+; CHECK-NEXT:    stdu 1, -32(1)
+; CHECK-NEXT:  .Lcfi0:
+; CHECK-NEXT:    .cfi_def_cfa_offset 32
+; CHECK-NEXT:  .Lcfi1:
+; CHECK-NEXT:    .cfi_offset lr, 16
+; CHECK-NEXT:    li 5, 2
+; CHECK-NEXT:    bl memcmp
+; CHECK-NEXT:    nop
+; CHECK-NEXT:    cntlzw 3, 3
+; CHECK-NEXT:    rlwinm 3, 3, 27, 31, 31
+; CHECK-NEXT:    addi 1, 1, 32
+; CHECK-NEXT:    ld 0, 16(1)
+; CHECK-NEXT:    mtlr 0
 ; CHECK-NEXT:    blr
   %m = tail call signext i32 @memcmp(i8* %X, i8* %Y, i64 2) nobuiltin
   %c = icmp eq i32 %m, 0
Index: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
@@ -2406,12 +2406,10 @@
   }
 
   LibFunc Func;
-  if (TLInfo->getLibFunc(*CI->getCalledFunction(), Func) &&
-      Func == LibFunc_memcmp) {
-    if (expandMemCmp(CI, TTI, TLI, DL)) {
-      ModifiedDT = true;
-      return true;
-    }
+  if (TLInfo->getLibFunc(ImmutableCallSite(CI), Func) &&
+      Func == LibFunc_memcmp && expandMemCmp(CI, TTI, TLI, DL)) {
+    ModifiedDT = true;
+    return true;
   }
   return false;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34043.101954.patch
Type: text/x-patch
Size: 2860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170608/7199e7df/attachment.bin>


More information about the llvm-commits mailing list