Skip to content

Commit 25a8d61

Browse files
committed
Revert "[Clang] Add __builtin_(elementwise|reduce)_(max|min)imum (llvm#110198)"
This reverts commit 9440420.
1 parent 4c0d805 commit 25a8d61

16 files changed

+94
-431
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 74 additions & 90 deletions
Large diffs are not rendered by default.

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ C++ Language Changes
144144

145145
- Add ``__builtin_elementwise_fmod`` builtin for floating point types only.
146146

147-
- Add ``__builtin_elementwise_minimum`` and ``__builtin_elementwise_maximum``
148-
builtin for floating point types only.
149-
150147
- The builtin type alias ``__builtin_common_type`` has been added to improve the
151148
performance of ``std::common_type``.
152149

clang/include/clang/Basic/Builtins.td

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,18 +1274,6 @@ def ElementwiseMin : Builtin {
12741274
let Prototype = "void(...)";
12751275
}
12761276

1277-
def ElementwiseMaximum : Builtin {
1278-
let Spellings = ["__builtin_elementwise_maximum"];
1279-
let Attributes = [NoThrow, Const, CustomTypeChecking];
1280-
let Prototype = "void(...)";
1281-
}
1282-
1283-
def ElementwiseMinimum : Builtin {
1284-
let Spellings = ["__builtin_elementwise_minimum"];
1285-
let Attributes = [NoThrow, Const, CustomTypeChecking];
1286-
let Prototype = "void(...)";
1287-
}
1288-
12891277
def ElementwiseCeil : Builtin {
12901278
let Spellings = ["__builtin_elementwise_ceil"];
12911279
let Attributes = [NoThrow, Const, CustomTypeChecking];
@@ -1460,18 +1448,6 @@ def ReduceMin : Builtin {
14601448
let Prototype = "void(...)";
14611449
}
14621450

1463-
def ReduceMaximum : Builtin {
1464-
let Spellings = ["__builtin_reduce_maximum"];
1465-
let Attributes = [NoThrow, Const, CustomTypeChecking];
1466-
let Prototype = "void(...)";
1467-
}
1468-
1469-
def ReduceMinimum : Builtin {
1470-
let Spellings = ["__builtin_reduce_minimum"];
1471-
let Attributes = [NoThrow, Const, CustomTypeChecking];
1472-
let Prototype = "void(...)";
1473-
}
1474-
14751451
def ReduceXor : Builtin {
14761452
let Spellings = ["__builtin_reduce_xor"];
14771453
let Attributes = [NoThrow, Const, CustomTypeChecking];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12221,8 +12221,7 @@ def err_builtin_invalid_arg_type: Error <
1222112221
"a floating point type|"
1222212222
"a vector of integers|"
1222312223
"an unsigned integer|"
12224-
"an 'int'|"
12225-
"a vector of floating points}1 (was %2)">;
12224+
"an 'int'}1 (was %2)">;
1222612225

1222712226
def err_builtin_matrix_disabled: Error<
1222812227
"matrix types extension is disabled. Pass -fenable-matrix to enable it">;

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,8 +2381,7 @@ class Sema final : public SemaBase {
23812381
bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
23822382
const FunctionProtoType *Proto);
23832383

2384-
/// \param FPOnly restricts the arguments to floating-point types.
2385-
bool BuiltinVectorMath(CallExpr *TheCall, QualType &Res, bool FPOnly = false);
2384+
bool BuiltinVectorMath(CallExpr *TheCall, QualType &Res);
23862385
bool BuiltinVectorToScalarMath(CallExpr *TheCall);
23872386

23882387
/// Handles the checks for format strings, non-POD arguments to vararg
@@ -2574,8 +2573,7 @@ class Sema final : public SemaBase {
25742573
ExprResult AtomicOpsOverloaded(ExprResult TheCallResult,
25752574
AtomicExpr::AtomicOp Op);
25762575

2577-
/// \param FPOnly restricts the arguments to floating-point types.
2578-
bool BuiltinElementwiseMath(CallExpr *TheCall, bool FPOnly = false);
2576+
bool BuiltinElementwiseMath(CallExpr *TheCall);
25792577
bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);
25802578

25812579
bool BuiltinNonDeterministicValue(CallExpr *TheCall);

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,22 +3964,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
39643964
return RValue::get(Result);
39653965
}
39663966

3967-
case Builtin::BI__builtin_elementwise_maximum: {
3968-
Value *Op0 = EmitScalarExpr(E->getArg(0));
3969-
Value *Op1 = EmitScalarExpr(E->getArg(1));
3970-
Value *Result = Builder.CreateBinaryIntrinsic(llvm::Intrinsic::maximum, Op0,
3971-
Op1, nullptr, "elt.maximum");
3972-
return RValue::get(Result);
3973-
}
3974-
3975-
case Builtin::BI__builtin_elementwise_minimum: {
3976-
Value *Op0 = EmitScalarExpr(E->getArg(0));
3977-
Value *Op1 = EmitScalarExpr(E->getArg(1));
3978-
Value *Result = Builder.CreateBinaryIntrinsic(llvm::Intrinsic::minimum, Op0,
3979-
Op1, nullptr, "elt.minimum");
3980-
return RValue::get(Result);
3981-
}
3982-
39833967
case Builtin::BI__builtin_reduce_max: {
39843968
auto GetIntrinsicID = [this](QualType QT) {
39853969
if (auto *VecTy = QT->getAs<VectorType>())
@@ -4032,12 +4016,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
40324016
case Builtin::BI__builtin_reduce_and:
40334017
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
40344018
*this, E, llvm::Intrinsic::vector_reduce_and, "rdx.and"));
4035-
case Builtin::BI__builtin_reduce_maximum:
4036-
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4037-
*this, E, llvm::Intrinsic::vector_reduce_fmaximum, "rdx.maximum"));
4038-
case Builtin::BI__builtin_reduce_minimum:
4039-
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4040-
*this, E, llvm::Intrinsic::vector_reduce_fminimum, "rdx.minimum"));
40414019

40424020
case Builtin::BI__builtin_matrix_transpose: {
40434021
auto *MatrixTy = E->getArg(0)->getType()->castAs<ConstantMatrixType>();

clang/lib/Sema/SemaChecking.cpp

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,12 +2755,17 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
27552755

27562756
// These builtins restrict the element type to floating point
27572757
// types only, and take in two arguments.
2758-
case Builtin::BI__builtin_elementwise_minimum:
2759-
case Builtin::BI__builtin_elementwise_maximum:
27602758
case Builtin::BI__builtin_elementwise_atan2:
27612759
case Builtin::BI__builtin_elementwise_fmod:
27622760
case Builtin::BI__builtin_elementwise_pow: {
2763-
if (BuiltinElementwiseMath(TheCall, /*FPOnly=*/true))
2761+
if (BuiltinElementwiseMath(TheCall))
2762+
return ExprError();
2763+
2764+
QualType ArgTy = TheCall->getArg(0)->getType();
2765+
if (checkFPMathBuiltinElementType(*this, TheCall->getArg(0)->getBeginLoc(),
2766+
ArgTy, 1) ||
2767+
checkFPMathBuiltinElementType(*this, TheCall->getArg(1)->getBeginLoc(),
2768+
ArgTy, 2))
27642769
return ExprError();
27652770
break;
27662771
}
@@ -2864,29 +2869,6 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
28642869
TheCall->setType(ElTy);
28652870
break;
28662871
}
2867-
case Builtin::BI__builtin_reduce_maximum:
2868-
case Builtin::BI__builtin_reduce_minimum: {
2869-
if (PrepareBuiltinReduceMathOneArgCall(TheCall))
2870-
return ExprError();
2871-
2872-
const Expr *Arg = TheCall->getArg(0);
2873-
const auto *TyA = Arg->getType()->getAs<VectorType>();
2874-
2875-
QualType ElTy;
2876-
if (TyA)
2877-
ElTy = TyA->getElementType();
2878-
else if (Arg->getType()->isSizelessVectorType())
2879-
ElTy = Arg->getType()->getSizelessVectorEltType(Context);
2880-
2881-
if (ElTy.isNull() || !ElTy->isFloatingType()) {
2882-
Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2883-
<< 1 << /* vector of floating points */ 9 << Arg->getType();
2884-
return ExprError();
2885-
}
2886-
2887-
TheCall->setType(ElTy);
2888-
break;
2889-
}
28902872

28912873
// These builtins support vectors of integers only.
28922874
// TODO: ADD/MUL should support floating-point types.
@@ -14397,9 +14379,9 @@ bool Sema::PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall) {
1439714379
return false;
1439814380
}
1439914381

14400-
bool Sema::BuiltinElementwiseMath(CallExpr *TheCall, bool FPOnly) {
14382+
bool Sema::BuiltinElementwiseMath(CallExpr *TheCall) {
1440114383
QualType Res;
14402-
if (BuiltinVectorMath(TheCall, Res, FPOnly))
14384+
if (BuiltinVectorMath(TheCall, Res))
1440314385
return true;
1440414386
TheCall->setType(Res);
1440514387
return false;
@@ -14418,7 +14400,7 @@ bool Sema::BuiltinVectorToScalarMath(CallExpr *TheCall) {
1441814400
return false;
1441914401
}
1442014402

14421-
bool Sema::BuiltinVectorMath(CallExpr *TheCall, QualType &Res, bool FPOnly) {
14403+
bool Sema::BuiltinVectorMath(CallExpr *TheCall, QualType &Res) {
1442214404
if (checkArgCount(TheCall, 2))
1442314405
return true;
1442414406

@@ -14438,13 +14420,8 @@ bool Sema::BuiltinVectorMath(CallExpr *TheCall, QualType &Res, bool FPOnly) {
1443814420
diag::err_typecheck_call_different_arg_types)
1443914421
<< TyA << TyB;
1444014422

14441-
if (FPOnly) {
14442-
if (checkFPMathBuiltinElementType(*this, A.get()->getBeginLoc(), TyA, 1))
14443-
return true;
14444-
} else {
14445-
if (checkMathBuiltinElementType(*this, A.get()->getBeginLoc(), TyA, 1))
14446-
return true;
14447-
}
14423+
if (checkMathBuiltinElementType(*this, A.get()->getBeginLoc(), TyA, 1))
14424+
return true;
1444814425

1444914426
TheCall->setArg(0, A.get());
1445014427
TheCall->setArg(1, B.get());

clang/test/CodeGen/builtins-elementwise-math.c

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -169,82 +169,6 @@ void test_builtin_elementwise_sub_sat(float f1, float f2, double d1, double d2,
169169
i1 = __builtin_elementwise_sub_sat(1, 'a');
170170
}
171171

172-
void test_builtin_elementwise_maximum(float f1, float f2, double d1, double d2,
173-
float4 vf1, float4 vf2, long long int i1,
174-
long long int i2, si8 vi1, si8 vi2,
175-
unsigned u1, unsigned u2, u4 vu1, u4 vu2,
176-
_BitInt(31) bi1, _BitInt(31) bi2,
177-
unsigned _BitInt(55) bu1, unsigned _BitInt(55) bu2) {
178-
// CHECK-LABEL: define void @test_builtin_elementwise_maximum(
179-
// CHECK: [[F1:%.+]] = load float, ptr %f1.addr, align 4
180-
// CHECK-NEXT: [[F2:%.+]] = load float, ptr %f2.addr, align 4
181-
// CHECK-NEXT: call float @llvm.maximum.f32(float [[F1]], float [[F2]])
182-
f1 = __builtin_elementwise_maximum(f1, f2);
183-
184-
// CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
185-
// CHECK-NEXT: [[D2:%.+]] = load double, ptr %d2.addr, align 8
186-
// CHECK-NEXT: call double @llvm.maximum.f64(double [[D1]], double [[D2]])
187-
d1 = __builtin_elementwise_maximum(d1, d2);
188-
189-
// CHECK: [[D2:%.+]] = load double, ptr %d2.addr, align 8
190-
// CHECK-NEXT: call double @llvm.maximum.f64(double 2.000000e+01, double [[D2]])
191-
d1 = __builtin_elementwise_maximum(20.0, d2);
192-
193-
// CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
194-
// CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
195-
// CHECK-NEXT: call <4 x float> @llvm.maximum.v4f32(<4 x float> [[VF1]], <4 x float> [[VF2]])
196-
vf1 = __builtin_elementwise_maximum(vf1, vf2);
197-
198-
// CHECK: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
199-
// CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
200-
// CHECK-NEXT: call <4 x float> @llvm.maximum.v4f32(<4 x float> [[CVF1]], <4 x float> [[VF2]])
201-
const float4 cvf1 = vf1;
202-
vf1 = __builtin_elementwise_maximum(cvf1, vf2);
203-
204-
// CHECK: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
205-
// CHECK-NEXT: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
206-
// CHECK-NEXT: call <4 x float> @llvm.maximum.v4f32(<4 x float> [[VF2]], <4 x float> [[CVF1]])
207-
vf1 = __builtin_elementwise_maximum(vf2, cvf1);
208-
}
209-
210-
void test_builtin_elementwise_minimum(float f1, float f2, double d1, double d2,
211-
float4 vf1, float4 vf2, long long int i1,
212-
long long int i2, si8 vi1, si8 vi2,
213-
unsigned u1, unsigned u2, u4 vu1, u4 vu2,
214-
_BitInt(31) bi1, _BitInt(31) bi2,
215-
unsigned _BitInt(55) bu1, unsigned _BitInt(55) bu2) {
216-
// CHECK-LABEL: define void @test_builtin_elementwise_minimum(
217-
// CHECK: [[F1:%.+]] = load float, ptr %f1.addr, align 4
218-
// CHECK-NEXT: [[F2:%.+]] = load float, ptr %f2.addr, align 4
219-
// CHECK-NEXT: call float @llvm.minimum.f32(float [[F1]], float [[F2]])
220-
f1 = __builtin_elementwise_minimum(f1, f2);
221-
222-
// CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
223-
// CHECK-NEXT: [[D2:%.+]] = load double, ptr %d2.addr, align 8
224-
// CHECK-NEXT: call double @llvm.minimum.f64(double [[D1]], double [[D2]])
225-
d1 = __builtin_elementwise_minimum(d1, d2);
226-
227-
// CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
228-
// CHECK-NEXT: call double @llvm.minimum.f64(double [[D1]], double 2.000000e+00)
229-
d1 = __builtin_elementwise_minimum(d1, 2.0);
230-
231-
// CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
232-
// CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
233-
// CHECK-NEXT: call <4 x float> @llvm.minimum.v4f32(<4 x float> [[VF1]], <4 x float> [[VF2]])
234-
vf1 = __builtin_elementwise_minimum(vf1, vf2);
235-
236-
// CHECK: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
237-
// CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
238-
// CHECK-NEXT: call <4 x float> @llvm.minimum.v4f32(<4 x float> [[CVF1]], <4 x float> [[VF2]])
239-
const float4 cvf1 = vf1;
240-
vf1 = __builtin_elementwise_minimum(cvf1, vf2);
241-
242-
// CHECK: [[VF2:%.+]] = load <4 x float>, ptr %vf2.addr, align 16
243-
// CHECK-NEXT: [[CVF1:%.+]] = load <4 x float>, ptr %cvf1, align 16
244-
// CHECK-NEXT: call <4 x float> @llvm.minimum.v4f32(<4 x float> [[VF2]], <4 x float> [[CVF1]])
245-
vf1 = __builtin_elementwise_minimum(vf2, cvf1);
246-
}
247-
248172
void test_builtin_elementwise_max(float f1, float f2, double d1, double d2,
249173
float4 vf1, float4 vf2, long long int i1,
250174
long long int i2, si8 vi1, si8 vi2,

clang/test/CodeGen/builtins-reduction-math.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,6 @@ void test_builtin_reduce_and(si8 vi1, u4 vu1) {
138138
unsigned r3 = __builtin_reduce_and(vu1);
139139
}
140140

141-
void test_builtin_reduce_maximum(float4 vf1) {
142-
// CHECK-LABEL: define void @test_builtin_reduce_maximum(
143-
// CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
144-
// CHECK-NEXT: call float @llvm.vector.reduce.fmaximum.v4f32(<4 x float> [[VF1]])
145-
float r1 = __builtin_reduce_maximum(vf1);
146-
147-
// CHECK: [[VF1_AS1:%.+]] = load <4 x float>, ptr addrspace(1) @vf1_as_one, align 16
148-
// CHECK-NEXT: [[RDX1:%.+]] = call float @llvm.vector.reduce.fmaximum.v4f32(<4 x float> [[VF1_AS1]])
149-
// CHECK-NEXT: fpext float [[RDX1]] to double
150-
const double r4 = __builtin_reduce_maximum(vf1_as_one);
151-
}
152-
153-
void test_builtin_reduce_minimum(float4 vf1) {
154-
// CHECK-LABEL: define void @test_builtin_reduce_minimum(
155-
// CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
156-
// CHECK-NEXT: call float @llvm.vector.reduce.fminimum.v4f32(<4 x float> [[VF1]])
157-
float r1 = __builtin_reduce_minimum(vf1);
158-
159-
// CHECK: [[VF1_AS1:%.+]] = load <4 x float>, ptr addrspace(1) @vf1_as_one, align 16
160-
// CHECK-NEXT: [[RDX1:%.+]] = call float @llvm.vector.reduce.fminimum.v4f32(<4 x float> [[VF1_AS1]])
161-
// CHECK-NEXT: fpext float [[RDX1]] to double
162-
const double r4 = __builtin_reduce_minimum(vf1_as_one);
163-
}
164-
165141
#if defined(__ARM_FEATURE_SVE)
166142
#include <arm_sve.h>
167143

clang/test/CodeGen/strictfp-elementwise-bulitins.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,6 @@ float4 strict_elementwise_min(float4 a, float4 b) {
4747
return __builtin_elementwise_min(a, b);
4848
}
4949

50-
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z26strict_elementwise_maximumDv4_fS_
51-
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
52-
// CHECK-NEXT: entry:
53-
// CHECK-NEXT: [[ELT_MAXIMUM:%.*]] = tail call <4 x float> @llvm.maximum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
54-
// CHECK-NEXT: ret <4 x float> [[ELT_MAXIMUM]]
55-
//
56-
float4 strict_elementwise_maximum(float4 a, float4 b) {
57-
return __builtin_elementwise_maximum(a, b);
58-
}
59-
60-
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z26strict_elementwise_minimumDv4_fS_
61-
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
62-
// CHECK-NEXT: entry:
63-
// CHECK-NEXT: [[ELT_MINIMUM:%.*]] = tail call <4 x float> @llvm.minimum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
64-
// CHECK-NEXT: ret <4 x float> [[ELT_MINIMUM]]
65-
//
66-
float4 strict_elementwise_minimum(float4 a, float4 b) {
67-
return __builtin_elementwise_minimum(a, b);
68-
}
69-
7050
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z23strict_elementwise_ceilDv4_f
7151
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
7252
// CHECK-NEXT: entry:

clang/test/Sema/aarch64-sve-vector-pow-ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
svfloat32_t test_pow_vv_i8mf8(svfloat32_t v) {
88

99
return __builtin_elementwise_pow(v, v);
10-
// expected-error@-1 {{1st argument must be a floating point type}}
10+
// expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
1111
}

0 commit comments

Comments
 (0)