When CodeGen'ing unoptimized code, there may be unfolded constant expressions

in global initializers. Instead of aborting, attempt to fold them on the
spot. If folding succeeds, emit the folded expression instead.

This fixes PR6255.

llvm-svn: 95583
This commit is contained in:
Dan Gohman 2010-02-08 22:02:38 +00:00
parent 6f9646e1c5
commit 4268d6a7c3
2 changed files with 17 additions and 9 deletions

View File

@ -25,6 +25,7 @@
#include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineLoopInfo.h" #include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/DebugInfo.h" #include "llvm/Analysis/DebugInfo.h"
#include "llvm/MC/MCContext.h" #include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h" #include "llvm/MC/MCExpr.h"
@ -887,15 +888,16 @@ static const MCExpr *LowerConstant(const Constant *CV, AsmPrinter &AP) {
} }
switch (CE->getOpcode()) { switch (CE->getOpcode()) {
case Instruction::ZExt: default:
case Instruction::SExt: // If the code isn't optimized, there may be outstanding folding
case Instruction::FPTrunc: // opportunities. Attempt to fold the expression using TargetData as a
case Instruction::FPExt: // last resort before giving up.
case Instruction::UIToFP: if (Constant *C = ConstantFoldConstantExpression(CE, AP.TM.getTargetData()))
case Instruction::SIToFP: return LowerConstant(C, AP);
case Instruction::FPToUI: #ifndef NDEBUG
case Instruction::FPToSI: CE->dump();
default: llvm_unreachable("FIXME: Don't support this constant cast expr"); #endif
llvm_unreachable("FIXME: Don't support this constant expr");
case Instruction::GetElementPtr: { case Instruction::GetElementPtr: {
const TargetData &TD = *AP.TM.getTargetData(); const TargetData &TD = *AP.TM.getTargetData();
// Generate a symbolic expression for the byte address // Generate a symbolic expression for the byte address

View File

@ -6,3 +6,9 @@
; CHECK: .quad r&4294967295 ; CHECK: .quad r&4294967295
@r = global %union.x { i64 ptrtoint (%union.x* @r to i64) }, align 4 @r = global %union.x { i64 ptrtoint (%union.x* @r to i64) }, align 4
; CHECK: .globl x
; CHECK: x:
; CHECK: .quad 3
@x = global i64 mul (i64 3, i64 ptrtoint (i2* getelementptr (i2* null, i64 1) to i64))