Skip to content

Commit 4bc2c0f

Browse files
aheejinyuxuanchen1997
authored andcommitted
[WebAssembly] Enable simd128 when relaxed-simd is set in AsmPrinter (#99803)
Summary: Even though in `Subtarget` we defined `SIMDLevel` as a number so `hasRelaxedSIMD` automatically means `hasSIMD128`, https://github.com/llvm/llvm-project/blob/0caf0c93e759816663af52e8632d1c3953dbc715/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h#L36-L40 https://github.com/llvm/llvm-project/blob/0caf0c93e759816663af52e8632d1c3953dbc715/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h#L107 specifying only `relaxed-simd` feature on a program that needs `simd128` instructions to compile fails, because of this query in `AsmPrinter`: https://github.com/llvm/llvm-project/blob/d0d05aec3b6792136a9f75eb85dd2ea66005ae12/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp#L644-L645 This `verifyInstructionPredicates` function (and other functions called by this function) is generated by https://github.com/llvm/llvm-project/blob/main/llvm/utils/TableGen/InstrInfoEmitter.cpp, and looks like this (you can check it in the `lib/Target/WebAssembly/WebAssemblyGenInstrInfo.inc` in your build directory): ```cpp void verifyInstructionPredicates( unsigned Opcode, const FeatureBitset &Features) { FeatureBitset AvailableFeatures = computeAvailableFeatures(Features); FeatureBitset RequiredFeatures = computeRequiredFeatures(Opcode); FeatureBitset MissingFeatures = (AvailableFeatures & RequiredFeatures) ^ RequiredFeatures; ... } ``` And `computeAvailableFeatures` is just a set query, like this: ```cpp inline FeatureBitset computeAvailableFeatures(const FeatureBitset &FB) { FeatureBitset Features; if (FB[WebAssembly::FeatureAtomics]) Features.set(Feature_HasAtomicsBit); if (FB[WebAssembly::FeatureBulkMemory]) Features.set(Feature_HasBulkMemoryBit); if (FB[WebAssembly::FeatureExceptionHandling]) Features.set(Feature_HasExceptionHandlingBit); ... ``` So this is how currently `HasSIMD128` is defined: https://github.com/llvm/llvm-project/blob/0caf0c93e759816663af52e8632d1c3953dbc715/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td#L79-L81 The things being checked in this `computeAvailableFeatures`, and in turn in `AsmPrinter`, are `AssemblerPredicate`s. These only check which bits are set in the features set and are different from `Predicate`s, which can call `Subtarget` functions like `Subtarget->hasSIMD128()`. But apparently we can use `all_of` and `any_of` directives in `AssemblerPredicate`, and we can make `simd128`'s `AssemblerPredicate` set in `relaxed-simd` is set by the condition as an 'or' of the two. Fixes #98502. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250795
1 parent f1676d8 commit 4bc2c0f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def HasSignExt :
7878

7979
def HasSIMD128 :
8080
Predicate<"Subtarget->hasSIMD128()">,
81-
AssemblerPredicate<(all_of FeatureSIMD128), "simd128">;
81+
AssemblerPredicate<(any_of FeatureSIMD128, FeatureRelaxedSIMD), "simd128">;
8282

8383
def HasTailCall :
8484
Predicate<"Subtarget->hasTailCall()">,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: llc < %s -verify-machineinstrs -mattr=+relaxed-simd | FileCheck %s
2+
3+
; Test that setting "relaxed-simd" target feature set also implies 'simd128' in
4+
; AssemblerPredicate, which is used to verify instructions in AsmPrinter.
5+
6+
target triple = "wasm32-unknown-unknown"
7+
8+
declare <2 x i64> @llvm.wasm.relaxed.laneselect.v2i64(<2 x i64>, <2 x i64>, <2 x i64>)
9+
10+
; The compiled result of this function uses LOCAL_GET_V128, which is predicated
11+
; on the 'simd128' feature. We should be able to compile this when only
12+
; 'relaxed-simd' is set, which implies 'simd128'.
13+
define <2 x i64> @test(<2 x i64>, <2 x i64>, <2 x i64>) #0 {
14+
; CHECK-LABEL: test:
15+
; CHECK: .functype test (v128, v128, v128) -> (v128)
16+
; CHECK-NEXT: # %bb.0:
17+
; CHECK-NEXT: local.get 0
18+
; CHECK-NEXT: local.get 1
19+
; CHECK-NEXT: local.get 2
20+
; CHECK-NEXT: i64x2.relaxed_laneselect
21+
start:
22+
%_4 = tail call <2 x i64> @llvm.wasm.relaxed.laneselect.v2i64(<2 x i64> %0, <2 x i64> %1, <2 x i64> %2) #3
23+
ret <2 x i64> %_4
24+
}

0 commit comments

Comments
 (0)