[llvm] e6c0164 - [ValueTracking] fix library to intrinsic mapping to respect 'nobuiltin' attribute

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 07:04:43 PDT 2020


Author: Sanjay Patel
Date: 2020-07-14T10:04:24-04:00
New Revision: e6c016420c796ac038b15e1ba0557947bf11d507

URL: https://github.com/llvm/llvm-project/commit/e6c016420c796ac038b15e1ba0557947bf11d507
DIFF: https://github.com/llvm/llvm-project/commit/e6c016420c796ac038b15e1ba0557947bf11d507.diff

LOG: [ValueTracking] fix library to intrinsic mapping to respect 'nobuiltin' attribute

This is another problem raised in:
http://bugs.llvm.org/PR46627

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp
    llvm/test/Transforms/InstSimplify/call.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index ffa2037fa10b..43caaa62c2ec 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3133,21 +3133,14 @@ Intrinsic::ID llvm::getIntrinsicForCallSite(const CallBase &CB,
   if (F->isIntrinsic())
     return F->getIntrinsicID();
 
-  if (!TLI)
-    return Intrinsic::not_intrinsic;
-
+  // We are going to infer semantics of a library function based on mapping it
+  // to an LLVM intrinsic. Check that the library function is available from
+  // this callbase and in this environment.
   LibFunc Func;
-  // We're going to make assumptions on the semantics of the functions, check
-  // that the target knows that it's available in this environment and it does
-  // not have local linkage.
-  if (!F || F->hasLocalLinkage() || !TLI->getLibFunc(*F, Func))
-    return Intrinsic::not_intrinsic;
-
-  if (!CB.onlyReadsMemory())
+  if (F->hasLocalLinkage() || !TLI || !TLI->getLibFunc(CB, Func) ||
+      !CB.onlyReadsMemory())
     return Intrinsic::not_intrinsic;
 
-  // Otherwise check if we have a call to a function that can be turned into a
-  // vector intrinsic.
   switch (Func) {
   default:
     break;

diff  --git a/llvm/test/Transforms/InstSimplify/call.ll b/llvm/test/Transforms/InstSimplify/call.ll
index 019def569f15..6579bda52795 100644
--- a/llvm/test/Transforms/InstSimplify/call.ll
+++ b/llvm/test/Transforms/InstSimplify/call.ll
@@ -1039,12 +1039,13 @@ define i32 @call_undef_musttail() {
   ret i32 %x
 }
 
-; FIXME: This is not the builtin fmax, so we don't know anything about its behavior.
+; This is not the builtin fmax, so we don't know anything about its behavior.
 
 define float @nobuiltin_fmax() {
 ; CHECK-LABEL: @nobuiltin_fmax(
 ; CHECK-NEXT:    [[M:%.*]] = call float @fmaxf(float 0.000000e+00, float 1.000000e+00) #3
-; CHECK-NEXT:    ret float [[M]]
+; CHECK-NEXT:    [[R:%.*]] = call float @llvm.fabs.f32(float [[M]])
+; CHECK-NEXT:    ret float [[R]]
 ;
   %m = call float @fmaxf(float 0.0, float 1.0) #0
   %r = call float @llvm.fabs.f32(float %m)


        


More information about the llvm-commits mailing list