Skip to content

Commit 0906908

Browse files
authored
[NVPTX] Add auto-upgrade rules for fabs.{f,d,ftz.f} (#136150)
These auto-upgrade rules are required after these intrinsics were removed in #135644
1 parent 9d5f163 commit 0906908

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,9 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
12871287
// nvvm.abs.{i,ii}
12881288
Expand =
12891289
Name == "i" || Name == "ll" || Name == "bf16" || Name == "bf16x2";
1290+
else if (Name == "fabs.f" || Name == "fabs.ftz.f" || Name == "fabs.d")
1291+
// nvvm.fabs.{f,ftz.f,d}
1292+
Expand = true;
12901293
else if (Name == "clz.ll" || Name == "popc.ll" || Name == "h2f" ||
12911294
Name == "swap.lo.hi.b64")
12921295
Expand = true;
@@ -2318,6 +2321,10 @@ static Value *upgradeNVVMIntrinsicCall(StringRef Name, CallBase *CI,
23182321
Value *Arg = Builder.CreateBitCast(CI->getArgOperand(0), Ty);
23192322
Value *Abs = Builder.CreateUnaryIntrinsic(Intrinsic::nvvm_fabs, Arg);
23202323
Rep = Builder.CreateBitCast(Abs, CI->getType());
2324+
} else if (Name == "fabs.f" || Name == "fabs.ftz.f" || Name == "fabs.d") {
2325+
Intrinsic::ID IID = (Name == "fabs.ftz.f") ? Intrinsic::nvvm_fabs_ftz
2326+
: Intrinsic::nvvm_fabs;
2327+
Rep = Builder.CreateUnaryIntrinsic(IID, CI->getArgOperand(0));
23212328
} else if (Name.starts_with("atomic.load.add.f32.p") ||
23222329
Name.starts_with("atomic.load.add.f64.p")) {
23232330
Value *Ptr = CI->getArgOperand(0);

llvm/test/Assembler/auto_upgrade_nvvm_intrinsics.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ declare float @llvm.nvvm.h2f(i16)
1313
declare i32 @llvm.nvvm.abs.i(i32)
1414
declare i64 @llvm.nvvm.abs.ll(i64)
1515

16+
declare float @llvm.nvvm.fabs.f(float)
17+
declare float @llvm.nvvm.fabs.ftz.f(float)
18+
declare double @llvm.nvvm.fabs.d(double)
19+
1620
declare i16 @llvm.nvvm.max.s(i16, i16)
1721
declare i32 @llvm.nvvm.max.i(i32, i32)
1822
declare i64 @llvm.nvvm.max.ll(i64, i64)
@@ -97,6 +101,17 @@ define void @abs(i32 %a, i64 %b) {
97101
ret void
98102
}
99103

104+
; CHECK-LABEL: @fabs
105+
define void @fabs(float %a, double %b) {
106+
; CHECK: call float @llvm.nvvm.fabs.f32(float %a)
107+
; CHECK: call float @llvm.nvvm.fabs.ftz.f32(float %a)
108+
; CHECK: call double @llvm.nvvm.fabs.f64(double %b)
109+
%r1 = call float @llvm.nvvm.fabs.f(float %a)
110+
%r2 = call float @llvm.nvvm.fabs.ftz.f(float %a)
111+
%r3 = call double @llvm.nvvm.fabs.d(double %b)
112+
ret void
113+
}
114+
100115
; CHECK-LABEL: @min_max
101116
define void @min_max(i16 %a1, i16 %a2, i32 %b1, i32 %b2, i64 %c1, i64 %c2) {
102117
; CHECK: [[maxs:%[a-zA-Z0-9.]+]] = icmp sge i16 %a1, %a2

0 commit comments

Comments
 (0)