[llvm] 8e70258 - [AMDGPUCodeGenPrepare] Check result of ConstantFoldBinaryOpOperands()

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 4 05:22:36 PDT 2022


Author: Nikita Popov
Date: 2022-07-04T14:20:23+02:00
New Revision: 8e70258b18ba35c5940dc8fa757b5bfb2ffb51d4

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

LOG: [AMDGPUCodeGenPrepare] Check result of ConstantFoldBinaryOpOperands()

This function will become fallible once we don't support constant
expressions for all binops, so make sure to check the result.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
index 94d7844e8a328..a8108b1d637bb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
@@ -626,13 +626,13 @@ bool AMDGPUCodeGenPrepare::foldBinOpIntoSelect(BinaryOperator &BO) const {
   Constant *FoldedT = SelOpNo ?
     ConstantFoldBinaryOpOperands(BO.getOpcode(), CBO, CT, *DL) :
     ConstantFoldBinaryOpOperands(BO.getOpcode(), CT, CBO, *DL);
-  if (isa<ConstantExpr>(FoldedT))
+  if (!FoldedT || isa<ConstantExpr>(FoldedT))
     return false;
 
   Constant *FoldedF = SelOpNo ?
     ConstantFoldBinaryOpOperands(BO.getOpcode(), CBO, CF, *DL) :
     ConstantFoldBinaryOpOperands(BO.getOpcode(), CF, CBO, *DL);
-  if (isa<ConstantExpr>(FoldedF))
+  if (!FoldedF || isa<ConstantExpr>(FoldedF))
     return false;
 
   IRBuilder<> Builder(&BO);


        


More information about the llvm-commits mailing list