- return ConstantFoldCompareInstOperands(CI->getPredicate(),
- &Ops[0], Ops.size(), TD);
- else
- return ConstantFoldInstOperands(I->getOpcode(), I->getType(),
- &Ops[0], Ops.size(), TD);
+ return ConstantFoldCompareInstOperands(CI->getPredicate(), Ops[0], Ops[1],
+ TD);
+
+ if (const LoadInst *LI = dyn_cast<LoadInst>(I))
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[0]))
+ if (!LI->isVolatile() && CE->getOpcode() == Instruction::GetElementPtr)
+ if (GlobalVariable *GV = dyn_cast<GlobalVariable>(CE->getOperand(0)))
+ if (GV->isConstant() && GV->hasDefinitiveInitializer())
+ return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(),
+ CE);
+
+ return ConstantFoldInstOperands(I->getOpcode(), I->getType(), &Ops[0],
+ Ops.size(), TD);
+}
+
+static MDNode *UpdateInlinedAtInfo(MDNode *InsnMD, MDNode *TheCallMD) {
+ DILocation ILoc(InsnMD);
+ if (!ILoc.Verify()) return InsnMD;
+
+ DILocation CallLoc(TheCallMD);
+ if (!CallLoc.Verify()) return InsnMD;
+
+ DILocation OrigLocation = ILoc.getOrigLocation();
+ MDNode *NewLoc = TheCallMD;
+ if (OrigLocation.Verify())
+ NewLoc = UpdateInlinedAtInfo(OrigLocation.getNode(), TheCallMD);
+
+ Value *MDVs[] = {
+ InsnMD->getOperand(0), // Line
+ InsnMD->getOperand(1), // Col
+ InsnMD->getOperand(2), // Scope
+ NewLoc
+ };
+ return MDNode::get(InsnMD->getContext(), MDVs, 4);