Skip to content

Commit

Permalink
[ValueTracking] fix library to intrinsic mapping to respect 'nobuilti…
Browse files Browse the repository at this point in the history
…n' attribute

This is another problem raised in:
http://bugs.llvm.org/PR46627
  • Loading branch information
rotateright committed Jul 14, 2020
1 parent 9300de4 commit e6c0164
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
17 changes: 5 additions & 12 deletions llvm/lib/Analysis/ValueTracking.cpp
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/Transforms/InstSimplify/call.ll
Expand Up @@ -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)
Expand Down

0 comments on commit e6c0164

Please sign in to comment.