Skip to content

Commit 7870b2f

Browse files
toppercmemfrob
authored andcommitted
[RISCV] Don't set the SplatOperand flag on intrinsics that take a shift amount.
The shift amount should always be a vector or an XLen scalar. The SplatOperand flag is used to indicate we need to legalize non-XLen scalars including special handling for i64 on RV32. This will prevent us from silently adjusting these operands if the intrinsics are misused. I'll probably adjust the name of the SplatOperand flag slightly in a follow up patch. Reviewed By: khchen, frasercrmck Differential Revision: https://reviews.llvm.org/D99545
1 parent 64d2c1c commit 7870b2f

File tree

1 file changed

+81
-20
lines changed

1 file changed

+81
-20
lines changed

llvm/include/llvm/IR/IntrinsicsRISCV.td

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ let TargetPrefix = "riscv" in {
291291
[IntrNoMem]>, RISCVVIntrinsic {
292292
let SplatOperand = 3;
293293
}
294+
// For destination vector type is the same as first source vector. The
295+
// second source operand must match the destination type or be an XLen scalar.
296+
// Input: (vector_in, vector_in/scalar_in, vl)
297+
class RISCVBinaryAAShiftNoMask
298+
: Intrinsic<[llvm_anyvector_ty],
299+
[LLVMMatchType<0>, llvm_any_ty, llvm_anyint_ty],
300+
[IntrNoMem]>, RISCVVIntrinsic;
301+
// For destination vector type is the same as first source vector (with mask).
302+
// The second source operand must match the destination type or be an XLen scalar.
303+
// Input: (maskedoff, vector_in, vector_in/scalar_in, mask, vl)
304+
class RISCVBinaryAAShiftMask
305+
: Intrinsic<[llvm_anyvector_ty],
306+
[LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
307+
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty],
308+
[IntrNoMem]>, RISCVVIntrinsic;
294309
// For destination vector type is NOT the same as first source vector.
295310
// Input: (vector_in, vector_in/scalar_in, vl)
296311
class RISCVBinaryABXNoMask
@@ -308,6 +323,21 @@ let TargetPrefix = "riscv" in {
308323
[IntrNoMem]>, RISCVVIntrinsic {
309324
let SplatOperand = 3;
310325
}
326+
// For destination vector type is NOT the same as first source vector. The
327+
// second source operand must match the destination type or be an XLen scalar.
328+
// Input: (vector_in, vector_in/scalar_in, vl)
329+
class RISCVBinaryABShiftNoMask
330+
: Intrinsic<[llvm_anyvector_ty],
331+
[llvm_anyvector_ty, llvm_any_ty, llvm_anyint_ty],
332+
[IntrNoMem]>, RISCVVIntrinsic;
333+
// For destination vector type is NOT the same as first source vector (with mask).
334+
// The second source operand must match the destination type or be an XLen scalar.
335+
// Input: (maskedoff, vector_in, vector_in/scalar_in, mask, vl)
336+
class RISCVBinaryABShiftMask
337+
: Intrinsic<[llvm_anyvector_ty],
338+
[LLVMMatchType<0>, llvm_anyvector_ty, llvm_any_ty,
339+
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty],
340+
[IntrNoMem]>, RISCVVIntrinsic;
311341
// For binary operations with V0 as input.
312342
// Input: (vector_in, vector_in/scalar_in, V0, vl)
313343
class RISCVBinaryWithV0
@@ -393,24 +423,39 @@ let TargetPrefix = "riscv" in {
393423
let SplatOperand = 3;
394424
}
395425
// For Saturating binary operations.
426+
// The destination vector type is the same as first source vector.
427+
// The second source operand matches the destination type or is an XLen scalar.
428+
// Input: (vector_in, vector_in/scalar_in, vl)
429+
class RISCVSaturatingBinaryAAShiftNoMask
430+
: Intrinsic<[llvm_anyvector_ty],
431+
[LLVMMatchType<0>, llvm_any_ty, llvm_anyint_ty],
432+
[IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic;
433+
// For Saturating binary operations with mask.
434+
// The destination vector type is the same as first source vector.
435+
// The second source operand matches the destination type or is an XLen scalar.
436+
// Input: (maskedoff, vector_in, vector_in/scalar_in, mask, vl)
437+
class RISCVSaturatingBinaryAAShiftMask
438+
: Intrinsic<[llvm_anyvector_ty],
439+
[LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
440+
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty],
441+
[IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic;
442+
// For Saturating binary operations.
396443
// The destination vector type is NOT the same as first source vector.
444+
// The second source operand matches the destination type or is an XLen scalar.
397445
// Input: (vector_in, vector_in/scalar_in, vl)
398-
class RISCVSaturatingBinaryABXNoMask
446+
class RISCVSaturatingBinaryABShiftNoMask
399447
: Intrinsic<[llvm_anyvector_ty],
400448
[llvm_anyvector_ty, llvm_any_ty, llvm_anyint_ty],
401-
[IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic {
402-
let SplatOperand = 2;
403-
}
449+
[IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic;
404450
// For Saturating binary operations with mask.
405451
// The destination vector type is NOT the same as first source vector (with mask).
452+
// The second source operand matches the destination type or is an XLen scalar.
406453
// Input: (maskedoff, vector_in, vector_in/scalar_in, mask, vl)
407-
class RISCVSaturatingBinaryABXMask
454+
class RISCVSaturatingBinaryABShiftMask
408455
: Intrinsic<[llvm_anyvector_ty],
409456
[LLVMMatchType<0>, llvm_anyvector_ty, llvm_any_ty,
410457
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty],
411-
[IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic {
412-
let SplatOperand = 3;
413-
}
458+
[IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic;
414459
class RISCVTernaryAAAXNoMask
415460
: Intrinsic<[llvm_anyvector_ty],
416461
[LLVMMatchType<0>, LLVMMatchType<0>, llvm_anyint_ty,
@@ -725,6 +770,12 @@ let TargetPrefix = "riscv" in {
725770
def "int_riscv_" # NAME : RISCVBinaryAAXNoMask;
726771
def "int_riscv_" # NAME # "_mask" : RISCVBinaryAAXMask;
727772
}
773+
// Like RISCVBinaryAAX, but the second operand is used a shift amount so it
774+
// must be a vector or an XLen scalar.
775+
multiclass RISCVBinaryAAShift {
776+
def "int_riscv_" # NAME : RISCVBinaryAAShiftNoMask;
777+
def "int_riscv_" # NAME # "_mask" : RISCVBinaryAAShiftMask;
778+
}
728779
multiclass RISCVRGatherVV {
729780
def "int_riscv_" # NAME : RISCVRGatherVVNoMask;
730781
def "int_riscv_" # NAME # "_mask" : RISCVRGatherVVMask;
@@ -743,6 +794,12 @@ let TargetPrefix = "riscv" in {
743794
def "int_riscv_" # NAME : RISCVBinaryABXNoMask;
744795
def "int_riscv_" # NAME # "_mask" : RISCVBinaryABXMask;
745796
}
797+
// Like RISCVBinaryABX, but the second operand is used a shift amount so it
798+
// must be a vector or an XLen scalar.
799+
multiclass RISCVBinaryABShift {
800+
def "int_riscv_" # NAME : RISCVBinaryABShiftNoMask;
801+
def "int_riscv_" # NAME # "_mask" : RISCVBinaryABShiftMask;
802+
}
746803
multiclass RISCVBinaryWithV0 {
747804
def "int_riscv_" # NAME : RISCVBinaryWithV0;
748805
}
@@ -756,9 +813,13 @@ let TargetPrefix = "riscv" in {
756813
def "int_riscv_" # NAME : RISCVSaturatingBinaryAAXNoMask;
757814
def "int_riscv_" # NAME # "_mask" : RISCVSaturatingBinaryAAXMask;
758815
}
759-
multiclass RISCVSaturatingBinaryABX {
760-
def "int_riscv_" # NAME : RISCVSaturatingBinaryABXNoMask;
761-
def "int_riscv_" # NAME # "_mask" : RISCVSaturatingBinaryABXMask;
816+
multiclass RISCVSaturatingBinaryAAShift {
817+
def "int_riscv_" # NAME : RISCVSaturatingBinaryAAShiftNoMask;
818+
def "int_riscv_" # NAME # "_mask" : RISCVSaturatingBinaryAAShiftMask;
819+
}
820+
multiclass RISCVSaturatingBinaryABShift {
821+
def "int_riscv_" # NAME : RISCVSaturatingBinaryABShiftNoMask;
822+
def "int_riscv_" # NAME # "_mask" : RISCVSaturatingBinaryABShiftMask;
762823
}
763824
multiclass RISCVTernaryAAAX {
764825
def "int_riscv_" # NAME : RISCVTernaryAAAXNoMask;
@@ -880,12 +941,12 @@ let TargetPrefix = "riscv" in {
880941
defm vor : RISCVBinaryAAX;
881942
defm vxor : RISCVBinaryAAX;
882943

883-
defm vsll : RISCVBinaryAAX;
884-
defm vsrl : RISCVBinaryAAX;
885-
defm vsra : RISCVBinaryAAX;
944+
defm vsll : RISCVBinaryAAShift;
945+
defm vsrl : RISCVBinaryAAShift;
946+
defm vsra : RISCVBinaryAAShift;
886947

887-
defm vnsrl : RISCVBinaryABX;
888-
defm vnsra : RISCVBinaryABX;
948+
defm vnsrl : RISCVBinaryABShift;
949+
defm vnsra : RISCVBinaryABShift;
889950

890951
defm vmseq : RISCVCompare;
891952
defm vmsne : RISCVCompare;
@@ -1023,11 +1084,11 @@ let TargetPrefix = "riscv" in {
10231084

10241085
defm vsmul : RISCVSaturatingBinaryAAX;
10251086

1026-
defm vssrl : RISCVSaturatingBinaryAAX;
1027-
defm vssra : RISCVSaturatingBinaryAAX;
1087+
defm vssrl : RISCVSaturatingBinaryAAShift;
1088+
defm vssra : RISCVSaturatingBinaryAAShift;
10281089

1029-
defm vnclipu : RISCVSaturatingBinaryABX;
1030-
defm vnclip : RISCVSaturatingBinaryABX;
1090+
defm vnclipu : RISCVSaturatingBinaryABShift;
1091+
defm vnclip : RISCVSaturatingBinaryABShift;
10311092

10321093
defm vmfeq : RISCVCompare;
10331094
defm vmfne : RISCVCompare;

0 commit comments

Comments
 (0)