From d536f2328ededb3aae6563c721c6134c735f1918 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 29 Jul 2016 03:27:26 +0000 Subject: [ConstnatFolding] Teach the folder how to fold ConstantVector A ConstantVector can have ConstantExpr operands and vice versa. However, the folder had no ability to fold ConstantVectors which, in some cases, was an optimization barrier. Instead, rephrase the folder in terms of Constants instead of ConstantExprs and teach callers how to deal with failure. llvm-svn: 277099 --- llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Target') diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp index f2bd585a8f3..e627be0b23d 100644 --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -1848,9 +1848,9 @@ void NVPTXAsmPrinter::bufferLEByte(const Constant *CPV, int Bytes, ConvertIntToBytes<>(ptr, int32); aggBuffer->addBytes(ptr, 4, Bytes); break; - } else if (const ConstantExpr *Cexpr = dyn_cast(CPV)) { - if (const ConstantInt *constInt = dyn_cast( - ConstantFoldConstantExpression(Cexpr, DL))) { + } else if (const auto *Cexpr = dyn_cast(CPV)) { + if (const auto *constInt = dyn_cast_or_null( + ConstantFoldConstant(Cexpr, DL))) { int int32 = (int)(constInt->getZExtValue()); ConvertIntToBytes<>(ptr, int32); aggBuffer->addBytes(ptr, 4, Bytes); @@ -1871,8 +1871,8 @@ void NVPTXAsmPrinter::bufferLEByte(const Constant *CPV, int Bytes, aggBuffer->addBytes(ptr, 8, Bytes); break; } else if (const ConstantExpr *Cexpr = dyn_cast(CPV)) { - if (const ConstantInt *constInt = dyn_cast( - ConstantFoldConstantExpression(Cexpr, DL))) { + if (const auto *constInt = dyn_cast_or_null( + ConstantFoldConstant(Cexpr, DL))) { long long int64 = (long long)(constInt->getZExtValue()); ConvertIntToBytes<>(ptr, int64); aggBuffer->addBytes(ptr, 8, Bytes); @@ -2074,8 +2074,8 @@ NVPTXAsmPrinter::lowerConstantForGV(const Constant *CV, bool ProcessingGeneric) // If the code isn't optimized, there may be outstanding folding // opportunities. Attempt to fold the expression using DataLayout as a // last resort before giving up. - if (Constant *C = ConstantFoldConstantExpression(CE, getDataLayout())) - if (C != CE) + if (Constant *C = ConstantFoldConstant(CE, getDataLayout())) + if (C && C != CE) return lowerConstantForGV(C, ProcessingGeneric); // Otherwise report the problem to the user. -- cgit v1.2.3