[PATCH] D69161: [IR] Allow fast math flags on calls with floating point array type.
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 18 03:19:40 PDT 2019
foad created this revision.
foad added reviewers: spatel, wristow, arsenm, hfinkel, aemerson, efriedma, cameron.mcinally, mcberg2017, jmolloy.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
This extends the rules for when a call instruction is deemed to be an
FPMathOperator, which is based on the type of the call (i.e. the return
type of the function being called). Previously we only allowed
floating-point and vector-of-floating-point types. Now we also allow
arrays (nested to any depth) of floating-point and
vector-of-floating-point types.
This was motivated by llpc, the pipeline compiler for AMD GPUs
(https://github.com/GPUOpen-Drivers/llpc). llpc has many math library
functions that operate on vectors, typically represented as <4 x float>,
and some that operate on matrices, typically represented as
[4 x <4 x float>], and it's useful to be able to decorate calls to all
of them with fast math flags.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69161
Files:
llvm/include/llvm/IR/Operator.h
llvm/unittests/IR/InstructionsTest.cpp
Index: llvm/unittests/IR/InstructionsTest.cpp
===================================================================
--- llvm/unittests/IR/InstructionsTest.cpp
+++ llvm/unittests/IR/InstructionsTest.cpp
@@ -1046,6 +1046,60 @@
FP->deleteValue();
}
+TEST(InstructionsTest, FPCallIsFPMathOperator) {
+ LLVMContext C;
+
+ Type *ITy = Type::getInt32Ty(C);
+ FunctionType *IFnTy = FunctionType::get(ITy, {});
+ Value *ICallee = Constant::getNullValue(IFnTy->getPointerTo());
+ std::unique_ptr<CallInst> ICall(CallInst::Create(IFnTy, ICallee, {}, ""));
+ EXPECT_FALSE(isa<FPMathOperator>(ICall));
+
+ Type *VITy = VectorType::get(ITy, 2);
+ FunctionType *VIFnTy = FunctionType::get(VITy, {});
+ Value *VICallee = Constant::getNullValue(VIFnTy->getPointerTo());
+ std::unique_ptr<CallInst> VICall(CallInst::Create(VIFnTy, VICallee, {}, ""));
+ EXPECT_FALSE(isa<FPMathOperator>(VICall));
+
+ Type *AITy = ArrayType::get(ITy, 2);
+ FunctionType *AIFnTy = FunctionType::get(AITy, {});
+ Value *AICallee = Constant::getNullValue(AIFnTy->getPointerTo());
+ std::unique_ptr<CallInst> AICall(CallInst::Create(AIFnTy, AICallee, {}, ""));
+ EXPECT_FALSE(isa<FPMathOperator>(AICall));
+
+ Type *FTy = Type::getFloatTy(C);
+ FunctionType *FFnTy = FunctionType::get(FTy, {});
+ Value *FCallee = Constant::getNullValue(FFnTy->getPointerTo());
+ std::unique_ptr<CallInst> FCall(CallInst::Create(FFnTy, FCallee, {}, ""));
+ EXPECT_TRUE(isa<FPMathOperator>(FCall));
+
+ Type *VFTy = VectorType::get(FTy, 2);
+ FunctionType *VFFnTy = FunctionType::get(VFTy, {});
+ Value *VFCallee = Constant::getNullValue(VFFnTy->getPointerTo());
+ std::unique_ptr<CallInst> VFCall(CallInst::Create(VFFnTy, VFCallee, {}, ""));
+ EXPECT_TRUE(isa<FPMathOperator>(VFCall));
+
+ Type *AFTy = ArrayType::get(FTy, 2);
+ FunctionType *AFFnTy = FunctionType::get(AFTy, {});
+ Value *AFCallee = Constant::getNullValue(AFFnTy->getPointerTo());
+ std::unique_ptr<CallInst> AFCall(CallInst::Create(AFFnTy, AFCallee, {}, ""));
+ EXPECT_TRUE(isa<FPMathOperator>(AFCall));
+
+ Type *AVFTy = ArrayType::get(VFTy, 2);
+ FunctionType *AVFFnTy = FunctionType::get(AVFTy, {});
+ Value *AVFCallee = Constant::getNullValue(AVFFnTy->getPointerTo());
+ std::unique_ptr<CallInst> AVFCall(
+ CallInst::Create(AVFFnTy, AVFCallee, {}, ""));
+ EXPECT_TRUE(isa<FPMathOperator>(AVFCall));
+
+ Type *AAVFTy = ArrayType::get(AVFTy, 2);
+ FunctionType *AAVFFnTy = FunctionType::get(AAVFTy, {});
+ Value *AAVFCallee = Constant::getNullValue(AAVFFnTy->getPointerTo());
+ std::unique_ptr<CallInst> AAVFCall(
+ CallInst::Create(AAVFFnTy, AAVFCallee, {}, ""));
+ EXPECT_TRUE(isa<FPMathOperator>(AAVFCall));
+}
+
TEST(InstructionsTest, FNegInstruction) {
LLVMContext Context;
Type *FltTy = Type::getFloatTy(Context);
Index: llvm/include/llvm/IR/Operator.h
===================================================================
--- llvm/include/llvm/IR/Operator.h
+++ llvm/include/llvm/IR/Operator.h
@@ -392,7 +392,10 @@
case Instruction::InsertElement:
return false;
default:
- return V->getType()->isFPOrFPVectorTy();
+ Type *Ty = V->getType();
+ while (ArrayType *ArrTy = dyn_cast<ArrayType>(Ty))
+ Ty = ArrTy->getElementType();
+ return Ty->isFPOrFPVectorTy();
}
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69161.225584.patch
Type: text/x-patch
Size: 3301 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191018/a0d8dc72/attachment.bin>
More information about the llvm-commits
mailing list