Skip to content

Commit 025b8af

Browse files
committed
PreISelIntrinsicLowering: Lower llvm.log to a loop if scalable vec arg
Similar to ab976a1, but for llvm.log.
1 parent f5d2996 commit 025b8af

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,13 +560,15 @@ bool PreISelIntrinsicLowering::lowerIntrinsics(Module &M) const {
560560
break;
561561
case Intrinsic::exp:
562562
case Intrinsic::exp2:
563+
case Intrinsic::log:
563564
Changed |= forEachCall(F, [&](CallInst *CI) {
564565
Type *Ty = CI->getArgOperand(0)->getType();
565566
if (!isa<ScalableVectorType>(Ty))
566567
return false;
567568
const TargetLowering *TL = TM->getSubtargetImpl(F)->getTargetLowering();
568569
unsigned Op = TL->IntrinsicIDToISD(F.getIntrinsicID());
569-
if (!TL->isOperationExpand(Op, EVT::getEVT(Ty)))
570+
if (Op == ISD::DELETED_NODE ||
571+
!TL->isOperationExpand(Op, EVT::getEVT(Ty)))
570572
return false;
571573
return lowerUnaryVectorIntrinsicAsLoop(M, CI);
572574
});

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,8 @@ int TargetLoweringBase::IntrinsicIDToISD(Intrinsic::ID ID) const {
18611861
return ISD::FEXP;
18621862
case Intrinsic::exp2:
18631863
return ISD::FEXP2;
1864+
case Intrinsic::log:
1865+
return ISD::FLOG;
18641866
default:
18651867
return ISD::DELETED_NODE;
18661868
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes=pre-isel-intrinsic-lowering -S < %s | FileCheck %s
3+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
4+
target triple = "aarch64"
5+
6+
define <vscale x 4 x float> @scalable_vec_log(<vscale x 4 x float> %input) {
7+
; CHECK-LABEL: define <vscale x 4 x float> @scalable_vec_log(
8+
; CHECK-SAME: <vscale x 4 x float> [[INPUT:%.*]]) {
9+
; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.vscale.i64()
10+
; CHECK-NEXT: [[TMP2:%.*]] = mul i64 [[TMP1]], 4
11+
; CHECK-NEXT: br label %[[BB3:.*]]
12+
; CHECK: [[BB3]]:
13+
; CHECK-NEXT: [[TMP4:%.*]] = phi i64 [ 0, [[TMP0:%.*]] ], [ [[TMP9:%.*]], %[[BB3]] ]
14+
; CHECK-NEXT: [[TMP5:%.*]] = phi <vscale x 4 x float> [ [[INPUT]], [[TMP0]] ], [ [[TMP8:%.*]], %[[BB3]] ]
15+
; CHECK-NEXT: [[TMP6:%.*]] = extractelement <vscale x 4 x float> [[TMP5]], i64 [[TMP4]]
16+
; CHECK-NEXT: [[TMP7:%.*]] = call float @llvm.log.f32(float [[TMP6]])
17+
; CHECK-NEXT: [[TMP8]] = insertelement <vscale x 4 x float> [[TMP5]], float [[TMP7]], i64 [[TMP4]]
18+
; CHECK-NEXT: [[TMP9]] = add i64 [[TMP4]], 1
19+
; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i64 [[TMP9]], [[TMP2]]
20+
; CHECK-NEXT: br i1 [[TMP10]], label %[[BB11:.*]], label %[[BB3]]
21+
; CHECK: [[BB11]]:
22+
; CHECK-NEXT: ret <vscale x 4 x float> [[TMP8]]
23+
;
24+
%output = call <vscale x 4 x float> @llvm.log.nxv4f32(<vscale x 4 x float> %input)
25+
ret <vscale x 4 x float> %output
26+
}
27+
28+
define <4 x float> @fixed_vec_log(<4 x float> %input) {
29+
; CHECK-LABEL: define <4 x float> @fixed_vec_log(
30+
; CHECK-SAME: <4 x float> [[INPUT:%.*]]) {
31+
; CHECK-NEXT: [[OUTPUT:%.*]] = call <4 x float> @llvm.log.v4f32(<4 x float> [[INPUT]])
32+
; CHECK-NEXT: ret <4 x float> [[OUTPUT]]
33+
;
34+
%output = call <4 x float> @llvm.log.v4f32(<4 x float> %input)
35+
ret <4 x float> %output
36+
}
37+
38+
declare <4 x float> @llvm.log.v4f32(<4 x float>) #0
39+
declare <vscale x 4 x float> @llvm.log.nxv4f32(<vscale x 4 x float>) #0
40+
41+
; CHECK: attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
42+
; CHECK-NEXT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
43+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

0 commit comments

Comments
 (0)