[llvm] 8de7297 - [AMDGPU] Pull out repeated getVecSize() calls. NFC.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 10 08:31:55 PST 2022


Author: Simon Pilgrim
Date: 2022-02-10T16:31:36Z
New Revision: 8de72973743ff5bcc72e0bdd0016b21dc6530352

URL: https://github.com/llvm/llvm-project/commit/8de72973743ff5bcc72e0bdd0016b21dc6530352
DIFF: https://github.com/llvm/llvm-project/commit/8de72973743ff5bcc72e0bdd0016b21dc6530352.diff

LOG: [AMDGPU] Pull out repeated getVecSize() calls. NFC.

This is guaranteed to be evaluated so we can avoid repeated calls.

Helps the static analyzer as it couldn't recognise that each getVecSize() would return the same value.

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
index bbbadfdfd4441..78e092b2e8727 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
@@ -1593,8 +1593,9 @@ bool AMDGPULibCalls::evaluateCall(CallInst *aCI, const FuncInfo &FInfo) {
 
   // max vector size is 16, and sincos will generate two results.
   double DVal0[16], DVal1[16];
+  int FuncVecSize = getVecSize(FInfo);
   bool hasTwoResults = (FInfo.getId() == AMDGPULibFunc::EI_SINCOS);
-  if (getVecSize(FInfo) == 1) {
+  if (FuncVecSize == 1) {
     if (!evaluateScalarMathFunc(FInfo, DVal0[0],
                                 DVal1[0], copr0, copr1, copr2)) {
       return false;
@@ -1603,7 +1604,7 @@ bool AMDGPULibCalls::evaluateCall(CallInst *aCI, const FuncInfo &FInfo) {
     ConstantDataVector *CDV0 = dyn_cast_or_null<ConstantDataVector>(copr0);
     ConstantDataVector *CDV1 = dyn_cast_or_null<ConstantDataVector>(copr1);
     ConstantDataVector *CDV2 = dyn_cast_or_null<ConstantDataVector>(copr2);
-    for (int i=0; i < getVecSize(FInfo); ++i) {
+    for (int i = 0; i < FuncVecSize; ++i) {
       Constant *celt0 = CDV0 ? CDV0->getElementAsConstant(i) : nullptr;
       Constant *celt1 = CDV1 ? CDV1->getElementAsConstant(i) : nullptr;
       Constant *celt2 = CDV2 ? CDV2->getElementAsConstant(i) : nullptr;
@@ -1616,19 +1617,19 @@ bool AMDGPULibCalls::evaluateCall(CallInst *aCI, const FuncInfo &FInfo) {
 
   LLVMContext &context = CI->getParent()->getParent()->getContext();
   Constant *nval0, *nval1;
-  if (getVecSize(FInfo) == 1) {
+  if (FuncVecSize == 1) {
     nval0 = ConstantFP::get(CI->getType(), DVal0[0]);
     if (hasTwoResults)
       nval1 = ConstantFP::get(CI->getType(), DVal1[0]);
   } else {
     if (getArgType(FInfo) == AMDGPULibFunc::F32) {
       SmallVector <float, 0> FVal0, FVal1;
-      for (int i=0; i < getVecSize(FInfo); ++i)
+      for (int i = 0; i < FuncVecSize; ++i)
         FVal0.push_back((float)DVal0[i]);
       ArrayRef<float> tmp0(FVal0);
       nval0 = ConstantDataVector::get(context, tmp0);
       if (hasTwoResults) {
-        for (int i=0; i < getVecSize(FInfo); ++i)
+        for (int i = 0; i < FuncVecSize; ++i)
           FVal1.push_back((float)DVal1[i]);
         ArrayRef<float> tmp1(FVal1);
         nval1 = ConstantDataVector::get(context, tmp1);


        


More information about the llvm-commits mailing list