Skip to content

Commit 19ada02

Browse files
authored
PreISelIntrinsicLowering: Lower llvm.log to a loop if scalable vec arg (#129744)
Similar to ab976a1, but for llvm.log.
1 parent 40a469f commit 19ada02

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,14 @@ bool PreISelIntrinsicLowering::lowerIntrinsics(Module &M) const {
587587
break;
588588
case Intrinsic::exp:
589589
case Intrinsic::exp2:
590+
case Intrinsic::log:
590591
Changed |= forEachCall(F, [&](CallInst *CI) {
591592
Type *Ty = CI->getArgOperand(0)->getType();
592593
if (!isa<ScalableVectorType>(Ty))
593594
return false;
594595
const TargetLowering *TL = TM->getSubtargetImpl(F)->getTargetLowering();
595596
unsigned Op = TL->IntrinsicIDToISD(F.getIntrinsicID());
597+
assert(Op != ISD::DELETED_NODE && "unsupported intrinsic");
596598
if (!TL->isOperationExpand(Op, EVT::getEVT(Ty)))
597599
return false;
598600
return lowerUnaryVectorIntrinsicAsLoop(M, CI);

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,8 @@ int TargetLoweringBase::IntrinsicIDToISD(Intrinsic::ID ID) const {
19241924
return ISD::FEXP;
19251925
case Intrinsic::exp2:
19261926
return ISD::FEXP2;
1927+
case Intrinsic::log:
1928+
return ISD::FLOG;
19271929
default:
19281930
return ISD::DELETED_NODE;
19291931
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 triple = "aarch64"
4+
5+
define <vscale x 4 x float> @scalable_vec_log(<vscale x 4 x float> %input) {
6+
; CHECK-LABEL: define <vscale x 4 x float> @scalable_vec_log(
7+
; CHECK-SAME: <vscale x 4 x float> [[INPUT:%.*]]) {
8+
; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.vscale.i64()
9+
; CHECK-NEXT: [[TMP2:%.*]] = mul nuw i64 [[TMP1]], 4
10+
; CHECK-NEXT: br label %[[BB3:.*]]
11+
; CHECK: [[BB3]]:
12+
; CHECK-NEXT: [[TMP4:%.*]] = phi i64 [ 0, [[TMP0:%.*]] ], [ [[TMP9:%.*]], %[[BB3]] ]
13+
; CHECK-NEXT: [[TMP5:%.*]] = phi <vscale x 4 x float> [ [[INPUT]], [[TMP0]] ], [ [[TMP8:%.*]], %[[BB3]] ]
14+
; CHECK-NEXT: [[TMP6:%.*]] = extractelement <vscale x 4 x float> [[TMP5]], i64 [[TMP4]]
15+
; CHECK-NEXT: [[TMP7:%.*]] = call float @llvm.log.f32(float [[TMP6]])
16+
; CHECK-NEXT: [[TMP8]] = insertelement <vscale x 4 x float> [[TMP5]], float [[TMP7]], i64 [[TMP4]]
17+
; CHECK-NEXT: [[TMP9]] = add i64 [[TMP4]], 1
18+
; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i64 [[TMP9]], [[TMP2]]
19+
; CHECK-NEXT: br i1 [[TMP10]], label %[[BB11:.*]], label %[[BB3]]
20+
; CHECK: [[BB11]]:
21+
; CHECK-NEXT: ret <vscale x 4 x float> [[TMP8]]
22+
;
23+
%output = call <vscale x 4 x float> @llvm.log.nxv4f32(<vscale x 4 x float> %input)
24+
ret <vscale x 4 x float> %output
25+
}
26+
27+
define <4 x float> @fixed_vec_log(<4 x float> %input) {
28+
; CHECK-LABEL: define <4 x float> @fixed_vec_log(
29+
; CHECK-SAME: <4 x float> [[INPUT:%.*]]) {
30+
; CHECK-NEXT: [[OUTPUT:%.*]] = call <4 x float> @llvm.log.v4f32(<4 x float> [[INPUT]])
31+
; CHECK-NEXT: ret <4 x float> [[OUTPUT]]
32+
;
33+
%output = call <4 x float> @llvm.log.v4f32(<4 x float> %input)
34+
ret <4 x float> %output
35+
}
36+
37+
declare <4 x float> @llvm.log.v4f32(<4 x float>) #0
38+
declare <vscale x 4 x float> @llvm.log.nxv4f32(<vscale x 4 x float>) #0
39+
40+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

0 commit comments

Comments
 (0)