Skip to content

Commit 27563e6

Browse files
committed
[DirectX] Specify overload type of DXIL Op exp2 precisely
Add a test to verify error generation for exp2 with overload type double. Use type property instead of record name string to identify precise type.
1 parent 9a231f5 commit 27563e6

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ def Sin : DXILOpMapping<13, unary, int_sin,
260260
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
261261
def Exp2 : DXILOpMapping<21, unary, int_exp2,
262262
"Returns the base 2 exponential, or 2**x, of the specified value."
263-
"exp2(x) = 2**x.">;
263+
"exp2(x) = 2**x.",
264+
[llvm_halforfloat_ty, LLVMMatchType<0>]>;
264265
def Frac : DXILOpMapping<22, unary, int_dx_frac,
265266
"Returns a fraction from 0 to 1 that represents the "
266267
"decimal part of the input.",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: not opt -S -dxil-op-lower %s 2>&1 | FileCheck %s
2+
3+
; DXIL operation exp2 does not support double overload type
4+
; CHECK: LLVM ERROR: Invalid Overload
5+
6+
define noundef double @exp2_double(double noundef %a) #0 {
7+
entry:
8+
%a.addr = alloca double, align 8
9+
store double %a, ptr %a.addr, align 8
10+
%0 = load double, ptr %a.addr, align 8
11+
%elt.exp2 = call double @llvm.exp2.f64(double %0)
12+
ret double %elt.exp2
13+
}

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,9 @@ static ParameterKind getParameterKind(const Record *R) {
9595
case MVT::Other:
9696
// Handle DXIL-specific overload types
9797
{
98-
auto RetKind = StringSwitch<ParameterKind>(R->getNameInitAsString())
99-
.Cases("llvm_i16ori32_ty", "llvm_halforfloat_ty",
100-
ParameterKind::OVERLOAD)
101-
.Default(ParameterKind::INVALID);
102-
if (RetKind != ParameterKind::INVALID) {
103-
return RetKind;
98+
if ((R->getValueAsInt("isHalfOrFloat")) ||
99+
(R->getValueAsInt("isI16OrI32"))) {
100+
return ParameterKind::OVERLOAD;
104101
}
105102
}
106103
LLVM_FALLTHROUGH;

0 commit comments

Comments
 (0)