On Aug 11, 2009, at 6:16 PM, Dan Gohman wrote: > Author: djg > Date: Tue Aug 11 20:16:29 2009 > New Revision: 78765 > > URL: http://llvm.org/viewvc/llvm-project?rev=78765&view=rev > Log: > Use the new nsw form of add for signed integer addition.
Daniel, does the driver currently eat the -fwrapv option? We should start forwarding it to clang and use it to turn off NSW adds. -Chris > > 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=78765&r1=78764&r2=78765&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Aug 11 20:16:29 2009 > @@ -741,7 +741,12 @@ > NextVal = llvm::ConstantInt::getTrue(VMContext); > } else if (isa<llvm::IntegerType>(InVal->getType())) { > NextVal = llvm::ConstantInt::get(InVal->getType(), AmountVal); > - NextVal = Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : > "dec"); > + > + // Signed integer overflow is undefined behavior. > + if (ValTy->isSignedIntegerType()) > + NextVal = Builder.CreateNSWAdd(InVal, NextVal, isInc ? > "inc" : "dec"); > + else > + NextVal = Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : > "dec"); > } else { > // Add the inc/dec to the real part. > if (InVal->getType() == llvm::Type::FloatTy) > @@ -1033,7 +1038,11 @@ > > if (Ops.LHS->getType()->isFPOrFPVector()) > return Builder.CreateFAdd(Ops.LHS, Ops.RHS, "add"); > - > + > + // Signed integer overflow is undefined behavior. > + if (Ops.Ty->isSignedIntegerType()) > + return Builder.CreateNSWAdd(Ops.LHS, Ops.RHS, "add"); > + > return Builder.CreateAdd(Ops.LHS, Ops.RHS, "add"); > } > > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
