-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Scalarizer][DirectX] Add support for scalarization of Target intrinsics #108776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===- DirectXTargetTransformInfo.cpp - DirectX TTI ---------------*- C++ | ||
//-*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "DirectXTargetTransformInfo.h" | ||
#include "llvm/IR/Intrinsics.h" | ||
#include "llvm/IR/IntrinsicsDirectX.h" | ||
|
||
bool llvm::DirectXTTIImpl::isTargetIntrinsicTriviallyScalarizable( | ||
Intrinsic::ID ID) const { | ||
switch (ID) { | ||
case Intrinsic::dx_frac: | ||
case Intrinsic::dx_rsqrt: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,55 @@ | ||
; RUN: opt -S -dxil-op-lower < %s | FileCheck %s | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s | ||
|
||
; Make sure dxil operation function calls for frac are generated for float and half. | ||
; CHECK:call float @dx.op.unary.f32(i32 22, float %{{.*}}) | ||
; CHECK:call half @dx.op.unary.f16(i32 22, half %{{.*}}) | ||
|
||
target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64" | ||
target triple = "dxil-pc-shadermodel6.7-library" | ||
define noundef half @frac_half(half noundef %a) { | ||
; CHECK-LABEL: define noundef half @frac_half( | ||
; CHECK-SAME: half noundef [[A:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[DX_FRAC1:%.*]] = call half @dx.op.unary.f16(i32 22, half [[A]]) | ||
; CHECK-NEXT: ret half [[DX_FRAC1]] | ||
; | ||
entry: | ||
%dx.frac = call half @llvm.dx.frac.f16(half %a) | ||
ret half %dx.frac | ||
} | ||
|
||
; Function Attrs: noinline nounwind optnone | ||
define noundef float @frac_float(float noundef %a) #0 { | ||
; CHECK-LABEL: define noundef float @frac_float( | ||
; CHECK-SAME: float noundef [[A:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[DX_FRAC1:%.*]] = call float @dx.op.unary.f32(i32 22, float [[A]]) | ||
; CHECK-NEXT: ret float [[DX_FRAC1]] | ||
; | ||
entry: | ||
%a.addr = alloca float, align 4 | ||
store float %a, ptr %a.addr, align 4 | ||
%0 = load float, ptr %a.addr, align 4 | ||
%dx.frac = call float @llvm.dx.frac.f32(float %0) | ||
%dx.frac = call float @llvm.dx.frac.f32(float %a) | ||
ret float %dx.frac | ||
} | ||
|
||
; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn | ||
declare float @llvm.dx.frac.f32(float) #1 | ||
|
||
; Function Attrs: noinline nounwind optnone | ||
define noundef half @frac_half(half noundef %a) #0 { | ||
define noundef <4 x float> @frac_float4(<4 x float> noundef %a) #0 { | ||
; CHECK-LABEL: define noundef <4 x float> @frac_float4( | ||
; CHECK-SAME: <4 x float> noundef [[A:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[A_I0:%.*]] = extractelement <4 x float> [[A]], i64 0 | ||
; CHECK-NEXT: [[DOTI04:%.*]] = call float @dx.op.unary.f32(i32 22, float [[A_I0]]) | ||
; CHECK-NEXT: [[A_I1:%.*]] = extractelement <4 x float> [[A]], i64 1 | ||
; CHECK-NEXT: [[DOTI13:%.*]] = call float @dx.op.unary.f32(i32 22, float [[A_I1]]) | ||
; CHECK-NEXT: [[A_I2:%.*]] = extractelement <4 x float> [[A]], i64 2 | ||
; CHECK-NEXT: [[DOTI22:%.*]] = call float @dx.op.unary.f32(i32 22, float [[A_I2]]) | ||
; CHECK-NEXT: [[A_I3:%.*]] = extractelement <4 x float> [[A]], i64 3 | ||
; CHECK-NEXT: [[DOTI31:%.*]] = call float @dx.op.unary.f32(i32 22, float [[A_I3]]) | ||
; CHECK-NEXT: [[DOTUPTO0:%.*]] = insertelement <4 x float> poison, float [[DOTI04]], i64 0 | ||
; CHECK-NEXT: [[DOTUPTO1:%.*]] = insertelement <4 x float> [[DOTUPTO0]], float [[DOTI13]], i64 1 | ||
; CHECK-NEXT: [[DOTUPTO2:%.*]] = insertelement <4 x float> [[DOTUPTO1]], float [[DOTI22]], i64 2 | ||
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x float> [[DOTUPTO2]], float [[DOTI31]], i64 3 | ||
; CHECK-NEXT: ret <4 x float> [[TMP0]] | ||
; | ||
entry: | ||
%a.addr = alloca half, align 2 | ||
store half %a, ptr %a.addr, align 2 | ||
%0 = load half, ptr %a.addr, align 2 | ||
%dx.frac = call half @llvm.dx.frac.f16(half %0) | ||
ret half %dx.frac | ||
%2 = call <4 x float> @llvm.dx.frac.v4f32(<4 x float> %a) | ||
ret <4 x float> %2 | ||
} | ||
|
||
declare half @llvm.dx.frac.f16(half) | ||
declare float @llvm.dx.frac.f32(float) | ||
declare <4 x float> @llvm.dx.frac.v4f32(<4 x float>) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,56 @@ | ||
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s | ||
|
||
; Make sure dxil operation function calls for rsqrt are generated for float and half. | ||
|
||
; CHECK-LABEL: rsqrt_float | ||
; CHECK: call float @dx.op.unary.f32(i32 25, float %{{.*}}) | ||
define noundef float @rsqrt_float(float noundef %a) { | ||
; CHECK-SAME: float noundef [[A:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[DX_RSQRT1:%.*]] = call float @dx.op.unary.f32(i32 25, float [[A]]) | ||
; CHECK-NEXT: ret float [[DX_RSQRT1]] | ||
; | ||
entry: | ||
%a.addr = alloca float, align 4 | ||
store float %a, ptr %a.addr, align 4 | ||
%0 = load float, ptr %a.addr, align 4 | ||
%dx.rsqrt = call float @llvm.dx.rsqrt.f32(float %0) | ||
%dx.rsqrt = call float @llvm.dx.rsqrt.f32(float %a) | ||
ret float %dx.rsqrt | ||
} | ||
|
||
; CHECK-LABEL: rsqrt_half | ||
; CHECK: call half @dx.op.unary.f16(i32 25, half %{{.*}}) | ||
define noundef half @rsqrt_half(half noundef %a) { | ||
; CHECK-SAME: half noundef [[A:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[DX_RSQRT1:%.*]] = call half @dx.op.unary.f16(i32 25, half [[A]]) | ||
; CHECK-NEXT: ret half [[DX_RSQRT1]] | ||
; | ||
entry: | ||
%a.addr = alloca half, align 2 | ||
store half %a, ptr %a.addr, align 2 | ||
%0 = load half, ptr %a.addr, align 2 | ||
%dx.rsqrt = call half @llvm.dx.rsqrt.f16(half %0) | ||
%dx.rsqrt = call half @llvm.dx.rsqrt.f16(half %a) | ||
ret half %dx.rsqrt | ||
} | ||
|
||
define noundef <4 x float> @rsqrt_float4(<4 x float> noundef %a) #0 { | ||
; CHECK-LABEL: define noundef <4 x float> @rsqrt_float4( | ||
; CHECK-SAME: <4 x float> noundef [[A:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[A_I0:%.*]] = extractelement <4 x float> [[A]], i64 0 | ||
; CHECK-NEXT: [[DOTI04:%.*]] = call float @dx.op.unary.f32(i32 25, float [[A_I0]]) | ||
; CHECK-NEXT: [[A_I1:%.*]] = extractelement <4 x float> [[A]], i64 1 | ||
; CHECK-NEXT: [[DOTI13:%.*]] = call float @dx.op.unary.f32(i32 25, float [[A_I1]]) | ||
; CHECK-NEXT: [[A_I2:%.*]] = extractelement <4 x float> [[A]], i64 2 | ||
; CHECK-NEXT: [[DOTI22:%.*]] = call float @dx.op.unary.f32(i32 25, float [[A_I2]]) | ||
; CHECK-NEXT: [[A_I3:%.*]] = extractelement <4 x float> [[A]], i64 3 | ||
; CHECK-NEXT: [[DOTI31:%.*]] = call float @dx.op.unary.f32(i32 25, float [[A_I3]]) | ||
; CHECK-NEXT: [[DOTUPTO0:%.*]] = insertelement <4 x float> poison, float [[DOTI04]], i64 0 | ||
; CHECK-NEXT: [[DOTUPTO1:%.*]] = insertelement <4 x float> [[DOTUPTO0]], float [[DOTI13]], i64 1 | ||
; CHECK-NEXT: [[DOTUPTO2:%.*]] = insertelement <4 x float> [[DOTUPTO1]], float [[DOTI22]], i64 2 | ||
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x float> [[DOTUPTO2]], float [[DOTI31]], i64 3 | ||
; CHECK-NEXT: ret <4 x float> [[TMP0]] | ||
; | ||
entry: | ||
%2 = call <4 x float> @llvm.dx.rsqrt.v4f32(<4 x float> %a) | ||
ret <4 x float> %2 | ||
} | ||
|
||
|
||
declare half @llvm.dx.rsqrt.f16(half) | ||
declare float @llvm.dx.rsqrt.f32(float) | ||
declare <4 x float> @llvm.dx.rsqrt.v4f32(<4 x float>) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.