Skip to content

Commit 6ce3969

Browse files
authored
[CIR] Implement __builtin_ia32_cmpnltps/cmpnltpd (#1908)
This PR adds supports for __builtin_ia32_cmpnltps/cmpnltpd. Depends on #1893.
1 parent ab27364 commit 6ce3969

File tree

2 files changed

+62
-14
lines changed

2 files changed

+62
-14
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,8 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
17401740
llvm_unreachable("cmpneqps NYI");
17411741
case X86::BI__builtin_ia32_cmpnltps:
17421742
case X86::BI__builtin_ia32_cmpnltpd:
1743-
llvm_unreachable("cmpnltps NYI");
1743+
return getVectorFCmpIR(cir::CmpOpKind::lt, /*shouldInvert=*/true,
1744+
/*isSignaling=*/true);
17441745
case X86::BI__builtin_ia32_cmpnleps:
17451746
case X86::BI__builtin_ia32_cmpnlepd:
17461747
return getVectorFCmpIR(cir::CmpOpKind::le, /*shouldInvert=*/true,

clang/test/CIR/CodeGen/builtin-fcmp-sse.c

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -emit-cir %s -o - | FileCheck %s --check-prefix=CIR
22
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -emit-llvm %s -o - | FileCheck %s -check-prefix=LLVM
3-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -emit-llvm %s -o - | FileCheck %s -check-prefix=OG
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -emit-llvm %s -o - | FileCheck %s -check-prefix=OGCG
44

55
typedef float __m128 __attribute__((__vector_size__(16), __aligned__(16)));
66
typedef double __m128d __attribute__((__vector_size__(16), __aligned__(16)));
77

88
__m128 test_cmpnleps(__m128 A, __m128 B) {
9-
109
// CIR-LABEL: @test_cmpnleps
1110
// CIR: [[CMP:%.*]] = cir.vec.cmp(le, [[A:%.*]], [[B:%.*]]) : !cir.vector<!cir.float x 4>, !cir.vector<!s32i x 4>
1211
// CIR: [[NOTCMP:%.*]] = cir.unary(not, [[CMP]]) : !cir.vector<!s32i x 4>, !cir.vector<!s32i x 4>
@@ -21,17 +20,16 @@ __m128 test_cmpnleps(__m128 A, __m128 B) {
2120
// LLVM-NEXT: [[CAST:%.*]] = bitcast <4 x i32> [[SEXT]] to <4 x float>
2221
// LLVM-NEXT: ret <4 x float> [[CAST]]
2322

24-
// OG-LABEL: test_cmpnleps
25-
// OG: [[CMP:%.*]] = fcmp ugt <4 x float> {{.*}}, {{.*}}
26-
// OG-NEXT: [[SEXT:%.*]] = sext <4 x i1> [[CMP]] to <4 x i32>
27-
// OG-NEXT: [[CAST:%.*]] = bitcast <4 x i32> [[SEXT]] to <4 x float>
28-
// OG-NEXT: ret <4 x float> [[CAST]]
23+
// OGCG-LABEL: test_cmpnleps
24+
// OGCG: [[CMP:%.*]] = fcmp ugt <4 x float> {{.*}}, {{.*}}
25+
// OGCG-NEXT: [[SEXT:%.*]] = sext <4 x i1> [[CMP]] to <4 x i32>
26+
// OGCG-NEXT: [[CAST:%.*]] = bitcast <4 x i32> [[SEXT]] to <4 x float>
27+
// OGCG-NEXT: ret <4 x float> [[CAST]]
2928
return __builtin_ia32_cmpnleps(A, B);
3029
}
3130

3231

3332
__m128d test_cmpnlepd(__m128d A, __m128d B) {
34-
3533
// CIR-LABEL: @test_cmpnlepd
3634
// CIR: [[CMP:%.*]] = cir.vec.cmp(le, [[A:%.*]], [[B:%.*]]) : !cir.vector<!cir.double x 2>, !cir.vector<!s64i x 2>
3735
// CIR-NEXT: [[NOTCMP:%.*]] = cir.unary(not, [[CMP]]) : !cir.vector<!s64i x 2>, !cir.vector<!s64i x 2>
@@ -46,10 +44,59 @@ __m128d test_cmpnlepd(__m128d A, __m128d B) {
4644
// LLVM-NEXT: [[CAST:%.*]] = bitcast <2 x i64> [[SEXT]] to <2 x double>
4745
// LLVM-NEXT: ret <2 x double> [[CAST]]
4846

49-
// OG-LABEL: test_cmpnlepd
50-
// OG: [[CMP:%.*]] = fcmp ugt <2 x double> {{.*}}, {{.*}}
51-
// OG-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[CMP]] to <2 x i64>
52-
// OG-NEXT: [[CAST:%.*]] = bitcast <2 x i64> [[SEXT]] to <2 x double>
53-
// OG-NEXT: ret <2 x double> [[CAST]]
47+
// OGCG-LABEL: test_cmpnlepd
48+
// OGCG: [[CMP:%.*]] = fcmp ugt <2 x double> {{.*}}, {{.*}}
49+
// OGCG-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[CMP]] to <2 x i64>
50+
// OGCG-NEXT: [[CAST:%.*]] = bitcast <2 x i64> [[SEXT]] to <2 x double>
51+
// OGCG-NEXT: ret <2 x double> [[CAST]]
5452
return __builtin_ia32_cmpnlepd(A, B);
5553
}
54+
55+
56+
__m128 test_cmpnltps(__m128 A, __m128 B) {
57+
// CIR-LABEL: @test_cmpnltps
58+
// CIR: [[CMP:%.*]] = cir.vec.cmp(lt, [[A:%.*]], [[B:%.*]]) : !cir.vector<!cir.float x 4>, !cir.vector<!s32i x 4>
59+
// CIR: [[NOTCMP:%.*]] = cir.unary(not, [[CMP]]) : !cir.vector<!s32i x 4>, !cir.vector<!s32i x 4>
60+
// CIR-NEXT: [[CAST:%.*]] = cir.cast(bitcast, [[NOTCMP:%.*]] : !cir.vector<!s32i x 4>), !cir.vector<!cir.float x 4>
61+
// CIR-NEXT: cir.store [[CAST]], [[ALLOCA:%.*]] : !cir.vector<!cir.float x 4>, !cir.ptr<!cir.vector<!cir.float x 4>>
62+
// CIR-NEXT: [[LD:%.*]] = cir.load [[ALLOCA]] :
63+
// CIR-NEXT: cir.return [[LD]] : !cir.vector<!cir.float x 4>
64+
65+
// LLVM-LABEL: test_cmpnltps
66+
// LLVM: [[CMP:%.*]] = fcmp uge <4 x float> {{.*}}, {{.*}}
67+
// LLVM-NEXT: [[SEXT:%.*]] = sext <4 x i1> [[CMP]] to <4 x i32>
68+
// LLVM-NEXT: [[CAST:%.*]] = bitcast <4 x i32> [[SEXT]] to <4 x float>
69+
// LLVM-NEXT: ret <4 x float> [[CAST]]
70+
71+
// OGCG-LABEL: test_cmpnltps
72+
// OGCG: [[CMP:%.*]] = fcmp uge <4 x float> {{.*}}, {{.*}}
73+
// OGCG-NEXT: [[SEXT:%.*]] = sext <4 x i1> [[CMP]] to <4 x i32>
74+
// OGCG-NEXT: [[CAST:%.*]] = bitcast <4 x i32> [[SEXT]] to <4 x float>
75+
// OGCG-NEXT: ret <4 x float> [[CAST]]
76+
return __builtin_ia32_cmpnltps(A, B);
77+
}
78+
79+
80+
__m128d test_cmpnltpd(__m128d A, __m128d B) {
81+
// CIR-LABEL: @test_cmpnltpd
82+
// CIR: [[CMP:%.*]] = cir.vec.cmp(lt, [[A:%.*]], [[B:%.*]]) : !cir.vector<!cir.double x 2>, !cir.vector<!s64i x 2>
83+
// CIR-NEXT: [[NOTCMP:%.*]] = cir.unary(not, [[CMP]]) : !cir.vector<!s64i x 2>, !cir.vector<!s64i x 2>
84+
// CIR-NEXT: [[CAST:%.*]] = cir.cast(bitcast, [[NOTCMP]] : !cir.vector<!s64i x 2>), !cir.vector<!cir.double x 2>
85+
// CIR-NEXT: cir.store [[CAST]], [[ALLOCA:%.*]] : !cir.vector<!cir.double x 2>, !cir.ptr<!cir.vector<!cir.double x 2>>
86+
// CIR-NEXT: [[LD:%.*]] = cir.load [[ALLOCA]] :
87+
// CIR-NEXT: cir.return [[LD]] : !cir.vector<!cir.double x 2>
88+
89+
// LLVM-LABEL: test_cmpnltpd
90+
// LLVM: [[CMP:%.*]] = fcmp uge <2 x double> {{.*}}, {{.*}}
91+
// LLVM-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[CMP]] to <2 x i64>
92+
// LLVM-NEXT: [[CAST:%.*]] = bitcast <2 x i64> [[SEXT]] to <2 x double>
93+
// LLVM-NEXT: ret <2 x double> [[CAST]]
94+
95+
// OGCG-LABEL: test_cmpnltpd
96+
// OGCG: [[CMP:%.*]] = fcmp uge <2 x double> {{.*}}, {{.*}}
97+
// OGCG-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[CMP]] to <2 x i64>
98+
// OGCG-NEXT: [[CAST:%.*]] = bitcast <2 x i64> [[SEXT]] to <2 x double>
99+
// OGCG-NEXT: ret <2 x double> [[CAST]]
100+
return __builtin_ia32_cmpnltpd(A, B);
101+
}
102+

0 commit comments

Comments
 (0)