-
Notifications
You must be signed in to change notification settings - Fork 68
Support arith select in VPTO LLVM lowering #890
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
zhangstevenunity
merged 1 commit into
hw-native-sys:main
from
mouliangyu:feature-vpto-support-arith-select
Jul 2, 2026
+126
−0
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| // This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| // CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| // Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| // THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| // INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| // See LICENSE in the root of the software repository for the full text of the License. | ||
|
|
||
| // RUN: ( mkdir -p %T && ptoas --pto-arch=a5 --pto-backend=vpto %s -o %t --mlir-print-ir-after=convert-func-to-llvm 2>&1 || true ) | FileCheck %s | ||
|
|
||
| module attributes {pto.target_arch = "a5", pto.kernel_kind = #pto.kernel_kind<vector>} { | ||
| func.func @arith_select_vreg(%cond: i1, %lhs_scalar: f32, %rhs_scalar: f32, | ||
| %dst: !pto.ptr<f32, ub>) attributes {pto.kernel} { | ||
| %c0 = arith.constant 0 : index | ||
| pto.vecscope { | ||
| %mask = pto.pset_b32 "PAT_ALL" : !pto.mask<b32> | ||
| %lhs = pto.vdup %lhs_scalar, %mask | ||
| : f32, !pto.mask<b32> -> !pto.vreg<64xf32> | ||
| %rhs = pto.vdup %rhs_scalar, %mask | ||
| : f32, !pto.mask<b32> -> !pto.vreg<64xf32> | ||
| %chosen = arith.select %cond, %lhs, %rhs : !pto.vreg<64xf32> | ||
| pto.vsts %chosen, %dst[%c0], %mask | ||
| : !pto.vreg<64xf32>, !pto.ptr<f32, ub>, !pto.mask<b32> | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func.func @arith_select_mask(%cond: i1, %value: f32, | ||
| %dst: !pto.ptr<f32, ub>) attributes {pto.kernel} { | ||
| %c0 = arith.constant 0 : index | ||
| pto.vecscope { | ||
| %all = pto.pset_b32 "PAT_ALL" : !pto.mask<b32> | ||
| %tail = pto.pge_b32 "PAT_VL4" : !pto.mask<b32> | ||
| %chosen_mask = arith.select %cond, %all, %tail : !pto.mask<b32> | ||
| %vec = pto.vdup %value, %all | ||
| : f32, !pto.mask<b32> -> !pto.vreg<64xf32> | ||
| pto.vsts %vec, %dst[%c0], %chosen_mask | ||
| : !pto.vreg<64xf32>, !pto.ptr<f32, ub>, !pto.mask<b32> | ||
| } | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: llvm.func @arith_select_vreg_mix_aiv | ||
| // CHECK: %[[LHS:.*]] = llvm.call @llvm.hivm.vdups{{.*}} | ||
| // CHECK: %[[RHS:.*]] = llvm.call @llvm.hivm.vdups{{.*}} | ||
| // CHECK: %[[CHOSEN:.*]] = llvm.select %arg0, %[[LHS]], %[[RHS]] : i1, vector<64xf32> | ||
| // CHECK: llvm.call @llvm.hivm.vstsx1.v64f32(%[[CHOSEN]] | ||
|
|
||
| // CHECK-LABEL: llvm.func @arith_select_mask_mix_aiv | ||
| // CHECK: %[[ALL:.*]] = llvm.call @llvm.hivm.pset.b32 | ||
| // CHECK: %[[TAIL:.*]] = llvm.call @llvm.hivm.pge.b32 | ||
| // CHECK: %[[CHOSEN_MASK:.*]] = llvm.select %arg0, %[[ALL]], %[[TAIL]] : i1, vector<256xi1> | ||
| // CHECK: llvm.call @llvm.hivm.vstsx1.v64f32({{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}, %[[CHOSEN_MASK]]) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
%Tis deprecated in LLVM lit because it is a shared directory across tests and can lead to race conditions or flakiness. Since lit automatically creates the directory containing%tbefore running the test,mkdir -p %Tis redundant and can be safely removed.