Skip to content

Commit 98bd284

Browse files
committed
Short circuit check
1 parent 6bfe0bc commit 98bd284

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

llvm/include/llvm/IR/Operator.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,21 @@ class FPMathOperator : public Operator {
268268
SubclassOptionalData = FMF.Flags;
269269
}
270270

271+
/// Returns true if `Ty` is composed of a single kind of float-poing type
272+
/// (possibly repeated within an aggregate).
273+
static bool isComposedOfHomogeneousFloatingPointTypes(Type *Ty) {
274+
if (auto *StructTy = dyn_cast<StructType>(Ty)) {
275+
if (!StructTy->isLiteral() || !StructTy->containsHomogeneousTypes())
276+
return false;
277+
Ty = StructTy->elements().front();
278+
} else if (auto *ArrayTy = dyn_cast<ArrayType>(Ty)) {
279+
do {
280+
Ty = ArrayTy->getElementType();
281+
} while ((ArrayTy = dyn_cast<ArrayType>(Ty)));
282+
}
283+
return Ty->isFPOrFPVectorTy();
284+
};
285+
271286
public:
272287
/// Test if this operation allows all non-strict floating-point transforms.
273288
bool isFast() const {
@@ -329,16 +344,8 @@ class FPMathOperator : public Operator {
329344
/// Returns true if `Ty` is a supported floating-point type for phi, select,
330345
/// or call FPMathOperators.
331346
static bool isSupportedFloatingPointType(Type *Ty) {
332-
if (auto *StructTy = dyn_cast<StructType>(Ty)) {
333-
if (!StructTy->isLiteral() || !StructTy->containsHomogeneousTypes())
334-
return false;
335-
Ty = StructTy->elements().front();
336-
} else if (auto *ArrayTy = dyn_cast<ArrayType>(Ty)) {
337-
do {
338-
Ty = ArrayTy->getElementType();
339-
} while ((ArrayTy = dyn_cast<ArrayType>(Ty)));
340-
}
341-
return Ty->isFPOrFPVectorTy();
347+
return Ty->isFPOrFPVectorTy() ||
348+
isComposedOfHomogeneousFloatingPointTypes(Ty);
342349
}
343350

344351
static bool classof(const Value *V) {

0 commit comments

Comments
 (0)