[cfe-commits] r134642 - /cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Bill Wendling
isanbard at gmail.com
Thu Jul 7 14:13:10 PDT 2011
Author: void
Date: Thu Jul 7 16:13:10 2011
New Revision: 134642
URL: http://llvm.org/viewvc/llvm-project?rev=134642&view=rev
Log:
Layout the code for trapping arithmetic so that the overflow case comes after
the normal case.
Before, for this:
$ cat t.c
int test(int x) { return x * 2; }
We would get this:
addl %edi, %edi
jno LBB0_2
## BB#1: ## %overflow
ud2
LBB0_2: ## %nooverflow
movl %edi, %eax
popq %rbp
ret
Now we get this:
addl %edi, %edi
jo LBB0_2
## BB#1: ## %nooverflow
movl %edi, %eax
popq %rbp
ret
LBB0_2: ## %overflow
ud2
<rdar://problem/8283919>
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=134642&r1=134641&r2=134642&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Jul 7 16:13:10 2011
@@ -1677,9 +1677,11 @@
void ScalarExprEmitter::EmitUndefinedBehaviorIntegerDivAndRemCheck(
const BinOpInfo &Ops,
llvm::Value *Zero, bool isDiv) {
- llvm::BasicBlock *overflowBB = CGF.createBasicBlock("overflow", CGF.CurFn);
+ llvm::Function::iterator insertPt = Builder.GetInsertBlock();
llvm::BasicBlock *contBB =
- CGF.createBasicBlock(isDiv ? "div.cont" : "rem.cont", CGF.CurFn);
+ CGF.createBasicBlock(isDiv ? "div.cont" : "rem.cont", CGF.CurFn,
+ llvm::next(insertPt));
+ llvm::BasicBlock *overflowBB = CGF.createBasicBlock("overflow", CGF.CurFn);
const llvm::IntegerType *Ty = cast<llvm::IntegerType>(Zero->getType());
@@ -1709,9 +1711,11 @@
if (Ops.Ty->isIntegerType())
EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero, true);
else if (Ops.Ty->isRealFloatingType()) {
+ llvm::Function::iterator insertPt = Builder.GetInsertBlock();
+ llvm::BasicBlock *DivCont = CGF.createBasicBlock("div.cont", CGF.CurFn,
+ llvm::next(insertPt));
llvm::BasicBlock *overflowBB = CGF.createBasicBlock("overflow",
CGF.CurFn);
- llvm::BasicBlock *DivCont = CGF.createBasicBlock("div.cont", CGF.CurFn);
CGF.Builder.CreateCondBr(Builder.CreateFCmpOEQ(Ops.RHS, Zero),
overflowBB, DivCont);
EmitOverflowBB(overflowBB);
@@ -1778,8 +1782,10 @@
// Branch in case of overflow.
llvm::BasicBlock *initialBB = Builder.GetInsertBlock();
+ llvm::Function::iterator insertPt = initialBB;
+ llvm::BasicBlock *continueBB = CGF.createBasicBlock("nooverflow", CGF.CurFn,
+ llvm::next(insertPt));
llvm::BasicBlock *overflowBB = CGF.createBasicBlock("overflow", CGF.CurFn);
- llvm::BasicBlock *continueBB = CGF.createBasicBlock("nooverflow", CGF.CurFn);
Builder.CreateCondBr(overflow, overflowBB, continueBB);
More information about the cfe-commits
mailing list