Skip to content

Commit adacbf6

Browse files
committed
[SystemZ] Add codegen support for llvm.roundeven
This is straightforward as we already had all the necessary instructions, they simply were not wired up. Also allows implementing the vec_round intrinsic via the standard llvm.roundeven IR instead of a platform intrinsic now.
1 parent dbbdc7e commit adacbf6

23 files changed

+619
-117
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21011,6 +21011,8 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
2101121011
CI = Intrinsic::experimental_constrained_nearbyint; break;
2101221012
case 1: ID = Intrinsic::round;
2101321013
CI = Intrinsic::experimental_constrained_round; break;
21014+
case 4: ID = Intrinsic::roundeven;
21015+
CI = Intrinsic::experimental_constrained_roundeven; break;
2101421016
case 5: ID = Intrinsic::trunc;
2101521017
CI = Intrinsic::experimental_constrained_trunc; break;
2101621018
case 6: ID = Intrinsic::ceil;

clang/test/CodeGen/SystemZ/builtins-systemz-vector-constrained.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ void test_float(void) {
4444
// CHECK: call <2 x double> @llvm.experimental.constrained.nearbyint.v2f64(<2 x double> %{{.*}})
4545
vd = __builtin_s390_vfidb(vd, 4, 1);
4646
// CHECK: call <2 x double> @llvm.experimental.constrained.round.v2f64(<2 x double> %{{.*}})
47+
vd = __builtin_s390_vfidb(vd, 4, 4);
48+
// CHECK: call <2 x double> @llvm.experimental.constrained.roundeven.v2f64(<2 x double> %{{.*}})
4749
vd = __builtin_s390_vfidb(vd, 4, 5);
4850
// CHECK: call <2 x double> @llvm.experimental.constrained.trunc.v2f64(<2 x double> %{{.*}})
4951
vd = __builtin_s390_vfidb(vd, 4, 6);
5052
// CHECK: call <2 x double> @llvm.experimental.constrained.ceil.v2f64(<2 x double> %{{.*}})
5153
vd = __builtin_s390_vfidb(vd, 4, 7);
5254
// CHECK: call <2 x double> @llvm.experimental.constrained.floor.v2f64(<2 x double> %{{.*}})
53-
vd = __builtin_s390_vfidb(vd, 4, 4);
54-
// CHECK: call <2 x double> @llvm.s390.vfidb(<2 x double> %{{.*}}, i32 4, i32 4)
55+
vd = __builtin_s390_vfidb(vd, 4, 3);
56+
// CHECK: call <2 x double> @llvm.s390.vfidb(<2 x double> %{{.*}}, i32 4, i32 3)
5557
}

clang/test/CodeGen/SystemZ/builtins-systemz-vector.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,14 @@ void test_float(void) {
593593
// CHECK: call <2 x double> @llvm.nearbyint.v2f64(<2 x double> %{{.*}})
594594
vd = __builtin_s390_vfidb(vd, 4, 1);
595595
// CHECK: call <2 x double> @llvm.round.v2f64(<2 x double> %{{.*}})
596+
vd = __builtin_s390_vfidb(vd, 4, 4);
597+
// CHECK: call <2 x double> @llvm.roundeven.v2f64(<2 x double> %{{.*}})
596598
vd = __builtin_s390_vfidb(vd, 4, 5);
597599
// CHECK: call <2 x double> @llvm.trunc.v2f64(<2 x double> %{{.*}})
598600
vd = __builtin_s390_vfidb(vd, 4, 6);
599601
// CHECK: call <2 x double> @llvm.ceil.v2f64(<2 x double> %{{.*}})
600602
vd = __builtin_s390_vfidb(vd, 4, 7);
601603
// CHECK: call <2 x double> @llvm.floor.v2f64(<2 x double> %{{.*}})
602-
vd = __builtin_s390_vfidb(vd, 4, 4);
603-
// CHECK: call <2 x double> @llvm.s390.vfidb(<2 x double> %{{.*}}, i32 4, i32 4)
604+
vd = __builtin_s390_vfidb(vd, 4, 3);
605+
// CHECK: call <2 x double> @llvm.s390.vfidb(<2 x double> %{{.*}}, i32 4, i32 3)
604606
}

clang/test/CodeGen/SystemZ/builtins-systemz-vector2-constrained.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ void test_float(void) {
5959
// CHECK: call <4 x float> @llvm.experimental.constrained.nearbyint.v4f32(<4 x float> %{{.*}}, metadata !{{.*}})
6060
vf = __builtin_s390_vfisb(vf, 4, 1);
6161
// CHECK: call <4 x float> @llvm.experimental.constrained.round.v4f32(<4 x float> %{{.*}}, metadata !{{.*}})
62+
vf = __builtin_s390_vfisb(vf, 4, 4);
63+
// CHECK: call <4 x float> @llvm.experimental.constrained.roundeven.v4f32(<4 x float> %{{.*}}, metadata !{{.*}})
6264
vf = __builtin_s390_vfisb(vf, 4, 5);
6365
// CHECK: call <4 x float> @llvm.experimental.constrained.trunc.v4f32(<4 x float> %{{.*}}, metadata !{{.*}})
6466
vf = __builtin_s390_vfisb(vf, 4, 6);
6567
// CHECK: call <4 x float> @llvm.experimental.constrained.ceil.v4f32(<4 x float> %{{.*}}, metadata !{{.*}})
6668
vf = __builtin_s390_vfisb(vf, 4, 7);
6769
// CHECK: call <4 x float> @llvm.experimental.constrained.floor.v4f32(<4 x float> %{{.*}}, metadata !{{.*}})
70+
vf = __builtin_s390_vfisb(vf, 4, 3);
71+
// CHECK: call <4 x float> @llvm.s390.vfisb(<4 x float> %{{.*}}, i32 4, i32 3)
6872
}
6973

clang/test/CodeGen/SystemZ/builtins-systemz-vector2.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ void test_float(void) {
125125
// CHECK: call <4 x float> @llvm.nearbyint.v4f32(<4 x float> %{{.*}})
126126
vf = __builtin_s390_vfisb(vf, 4, 1);
127127
// CHECK: call <4 x float> @llvm.round.v4f32(<4 x float> %{{.*}})
128+
vf = __builtin_s390_vfisb(vf, 4, 4);
129+
// CHECK: call <4 x float> @llvm.roundeven.v4f32(<4 x float> %{{.*}})
128130
vf = __builtin_s390_vfisb(vf, 4, 5);
129131
// CHECK: call <4 x float> @llvm.trunc.v4f32(<4 x float> %{{.*}})
130132
vf = __builtin_s390_vfisb(vf, 4, 6);
131133
// CHECK: call <4 x float> @llvm.ceil.v4f32(<4 x float> %{{.*}})
132134
vf = __builtin_s390_vfisb(vf, 4, 7);
133135
// CHECK: call <4 x float> @llvm.floor.v4f32(<4 x float> %{{.*}})
134-
vf = __builtin_s390_vfisb(vf, 4, 4);
135-
// CHECK: call <4 x float> @llvm.s390.vfisb(<4 x float> %{{.*}}, i32 4, i32 4)
136+
vf = __builtin_s390_vfisb(vf, 4, 3);
137+
// CHECK: call <4 x float> @llvm.s390.vfisb(<4 x float> %{{.*}}, i32 4, i32 3)
136138
}
137139

clang/test/CodeGen/SystemZ/builtins-systemz-zvector-constrained.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,6 @@ void test_float(void) {
315315
// CHECK: call <2 x double> @llvm.experimental.constrained.rint.v2f64(<2 x double> %{{.*}}, metadata !{{.*}})
316316
// CHECK-ASM: vfidb %{{.*}}, %{{.*}}, 0, 0
317317
vd = vec_round(vd);
318+
// CHECK: call <2 x double> @llvm.experimental.constrained.roundeven.v2f64(<2 x double> %{{.*}}, metadata !{{.*}})
319+
// CHECK-ASM: vfidb %{{.*}}, %{{.*}}, 4, 4
318320
}

clang/test/CodeGen/SystemZ/builtins-systemz-zvector.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4889,7 +4889,7 @@ void test_float(void) {
48894889
// CHECK: call <2 x double> @llvm.rint.v2f64(<2 x double> %{{.*}})
48904890
// CHECK-ASM: vfidb %{{.*}}, %{{.*}}, 0, 0
48914891
vd = vec_round(vd);
4892-
// CHECK: call <2 x double> @llvm.s390.vfidb(<2 x double> %{{.*}}, i32 4, i32 4)
4892+
// CHECK: call <2 x double> @llvm.roundeven.v2f64(<2 x double> %{{.*}})
48934893
// CHECK-ASM: vfidb %{{.*}}, %{{.*}}, 4, 4
48944894

48954895
vbl = vec_fp_test_data_class(vd, 0, &cc);

clang/test/CodeGen/SystemZ/builtins-systemz-zvector2-constrained.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ void test_float(void) {
522522
// CHECK-ASM: vfidb %{{.*}}, %{{.*}}, 0, 0
523523

524524
vf = vec_round(vf);
525-
// CHECK: call <4 x float> @llvm.s390.vfisb(<4 x float> %{{.*}}, i32 4, i32 4)
525+
// CHECK: call <4 x float> @llvm.experimental.constrained.roundeven.v4f32(<4 x float> %{{.*}}, metadata !{{.*}})
526526
// CHECK-ASM: vfisb %{{.*}}, %{{.*}}, 4, 4
527527
vd = vec_round(vd);
528-
// CHECK: call <2 x double> @llvm.s390.vfidb(<2 x double> %{{.*}}, i32 4, i32 4)
528+
// CHECK: call <2 x double> @llvm.experimental.constrained.roundeven.v2f64(<2 x double> %{{.*}}, metadata !{{.*}})
529529
// CHECK-ASM: vfidb %{{.*}}, %{{.*}}, 4, 4
530530

531531
vbi = vec_fp_test_data_class(vf, 0, &cc);

clang/test/CodeGen/SystemZ/builtins-systemz-zvector2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,10 @@ void test_float(void) {
908908
// CHECK-ASM: vfidb %{{.*}}, %{{.*}}, 0, 0
909909

910910
vf = vec_round(vf);
911-
// CHECK: call <4 x float> @llvm.s390.vfisb(<4 x float> %{{.*}}, i32 4, i32 4)
911+
// CHECK: call <4 x float> @llvm.roundeven.v4f32(<4 x float> %{{.*}})
912912
// CHECK-ASM: vfisb %{{.*}}, %{{.*}}, 4, 4
913913
vd = vec_round(vd);
914-
// CHECK: call <2 x double> @llvm.s390.vfidb(<2 x double> %{{.*}}, i32 4, i32 4)
914+
// CHECK: call <2 x double> @llvm.roundeven.v2f64(<2 x double> %{{.*}})
915915
// CHECK-ASM: vfidb %{{.*}}, %{{.*}}, 4, 4
916916

917917
vbi = vec_fp_test_data_class(vf, 0, &cc);

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
556556
setOperationAction(ISD::FCEIL, VT, Legal);
557557
setOperationAction(ISD::FTRUNC, VT, Legal);
558558
setOperationAction(ISD::FROUND, VT, Legal);
559+
setOperationAction(ISD::FROUNDEVEN, VT, Legal);
559560
}
560561

561562
// No special instructions for these.
@@ -582,8 +583,9 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
582583
setOperationAction(ISD::STRICT_FNEARBYINT, VT, Legal);
583584
setOperationAction(ISD::STRICT_FFLOOR, VT, Legal);
584585
setOperationAction(ISD::STRICT_FCEIL, VT, Legal);
585-
setOperationAction(ISD::STRICT_FROUND, VT, Legal);
586586
setOperationAction(ISD::STRICT_FTRUNC, VT, Legal);
587+
setOperationAction(ISD::STRICT_FROUND, VT, Legal);
588+
setOperationAction(ISD::STRICT_FROUNDEVEN, VT, Legal);
587589
}
588590
}
589591
}
@@ -616,6 +618,7 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
616618
setOperationAction(ISD::FCEIL, MVT::v2f64, Legal);
617619
setOperationAction(ISD::FTRUNC, MVT::v2f64, Legal);
618620
setOperationAction(ISD::FROUND, MVT::v2f64, Legal);
621+
setOperationAction(ISD::FROUNDEVEN, MVT::v2f64, Legal);
619622

620623
// Handle constrained floating-point operations.
621624
setOperationAction(ISD::STRICT_FADD, MVT::v2f64, Legal);
@@ -630,6 +633,7 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
630633
setOperationAction(ISD::STRICT_FCEIL, MVT::v2f64, Legal);
631634
setOperationAction(ISD::STRICT_FTRUNC, MVT::v2f64, Legal);
632635
setOperationAction(ISD::STRICT_FROUND, MVT::v2f64, Legal);
636+
setOperationAction(ISD::STRICT_FROUNDEVEN, MVT::v2f64, Legal);
633637

634638
setOperationAction(ISD::SETCC, MVT::v2f64, Custom);
635639
setOperationAction(ISD::SETCC, MVT::v4f32, Custom);
@@ -657,6 +661,7 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
657661
setOperationAction(ISD::FCEIL, MVT::v4f32, Legal);
658662
setOperationAction(ISD::FTRUNC, MVT::v4f32, Legal);
659663
setOperationAction(ISD::FROUND, MVT::v4f32, Legal);
664+
setOperationAction(ISD::FROUNDEVEN, MVT::v4f32, Legal);
660665

661666
setOperationAction(ISD::FMAXNUM, MVT::f64, Legal);
662667
setOperationAction(ISD::FMAXIMUM, MVT::f64, Legal);
@@ -694,8 +699,9 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
694699
setOperationAction(ISD::STRICT_FNEARBYINT, MVT::v4f32, Legal);
695700
setOperationAction(ISD::STRICT_FFLOOR, MVT::v4f32, Legal);
696701
setOperationAction(ISD::STRICT_FCEIL, MVT::v4f32, Legal);
697-
setOperationAction(ISD::STRICT_FROUND, MVT::v4f32, Legal);
698702
setOperationAction(ISD::STRICT_FTRUNC, MVT::v4f32, Legal);
703+
setOperationAction(ISD::STRICT_FROUND, MVT::v4f32, Legal);
704+
setOperationAction(ISD::STRICT_FROUNDEVEN, MVT::v4f32, Legal);
699705
for (auto VT : { MVT::f32, MVT::f64, MVT::f128,
700706
MVT::v4f32, MVT::v2f64 }) {
701707
setOperationAction(ISD::STRICT_FMAXNUM, VT, Legal);

0 commit comments

Comments
 (0)