[cfe-commits] r106955 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/builtins-ppc-altivec.c test/CodeGen/exprs.c test/CodeGenCXX/pointers-to-data-members.cpp
Chris Lattner
sabre at nondot.org
Sat Jun 26 13:27:24 PDT 2010
Author: lattner
Date: Sat Jun 26 15:27:24 2010
New Revision: 106955
URL: http://llvm.org/viewvc/llvm-project?rev=106955&view=rev
Log:
implement rdar://7432000 - signed negate should codegen as NSW.
While I'm in there, adjust pointer to member adjustments as well.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/builtins-ppc-altivec.c
cfe/trunk/test/CodeGen/exprs.c
cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=106955&r1=106954&r2=106955&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Jun 26 15:27:24 2010
@@ -997,13 +997,13 @@
std::swap(DerivedDecl, BaseDecl);
if (llvm::Constant *Adj =
- CGF.CGM.GetNonVirtualBaseClassOffset(DerivedDecl,
- CE->getBasePath())) {
+ CGF.CGM.GetNonVirtualBaseClassOffset(DerivedDecl, CE->getBasePath())){
if (CE->getCastKind() == CastExpr::CK_DerivedToBaseMemberPointer)
- Src = Builder.CreateSub(Src, Adj, "adj");
+ Src = Builder.CreateNSWSub(Src, Adj, "adj");
else
- Src = Builder.CreateAdd(Src, Adj, "adj");
+ Src = Builder.CreateNSWAdd(Src, Adj, "adj");
}
+
return Src;
}
@@ -1117,6 +1117,11 @@
Value *Op = Visit(E->getSubExpr());
if (Op->getType()->isFPOrFPVectorTy())
return Builder.CreateFNeg(Op, "neg");
+
+ // Signed integer overflow is undefined behavior.
+ if (E->getType()->isSignedIntegerType())
+ return Builder.CreateNSWNeg(Op, "neg");
+
return Builder.CreateNeg(Op, "neg");
}
Modified: cfe/trunk/test/CodeGen/builtins-ppc-altivec.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-altivec.c?rev=106955&r1=106954&r2=106955&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins-ppc-altivec.c (original)
+++ cfe/trunk/test/CodeGen/builtins-ppc-altivec.c Sat Jun 26 15:27:24 2010
@@ -43,13 +43,13 @@
int res_i;
/* vec_abs */
- vsc = vec_abs(vsc); // CHECK: sub <16 x i8> zeroinitializer
+ vsc = vec_abs(vsc); // CHECK: sub nsw <16 x i8> zeroinitializer
// CHECK: @llvm.ppc.altivec.vmaxsb
- vs = vec_abs(vs); // CHECK: sub <8 x i16> zeroinitializer
+ vs = vec_abs(vs); // CHECK: sub nsw <8 x i16> zeroinitializer
// CHECK: @llvm.ppc.altivec.vmaxsh
- vi = vec_abs(vi); // CHECK: sub <4 x i32> zeroinitializer
+ vi = vec_abs(vi); // CHECK: sub nsw <4 x i32> zeroinitializer
// CHECK: @llvm.ppc.altivec.vmaxsw
vf = vec_abs(vf); // CHECK: and <4 x i32>
Modified: cfe/trunk/test/CodeGen/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exprs.c?rev=106955&r1=106954&r2=106955&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/exprs.c (original)
+++ cfe/trunk/test/CodeGen/exprs.c Sat Jun 26 15:27:24 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -emit-llvm -o -
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
// PR1895
// sizeof function
@@ -119,3 +119,16 @@
void f10() {
__builtin_sin(0);
}
+
+// Tests for signed integer overflow stuff.
+// rdar://7432000
+void f11() {
+ // CHECK: define void @f11
+ extern volatile int f11G, a, b;
+ // CHECK: add nsw i32
+ f11G = a + b;
+ // CHECK: sub nsw i32
+ f11G = a - b;
+ // CHECK: sub nsw i32 0,
+ f11G = -a;
+}
Modified: cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp?rev=106955&r1=106954&r2=106955&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/pointers-to-data-members.cpp Sat Jun 26 15:27:24 2010
@@ -68,11 +68,11 @@
// CHECK: store i64 -1, i64* @_ZN5Casts2paE
pa = 0;
- // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = add i64 {{.*}}, 4
+ // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = add nsw i64 {{.*}}, 4
// CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2pcE
pc = pa;
- // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = sub i64 {{.*}}, 4
+ // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = sub nsw i64 {{.*}}, 4
// CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2paE
pa = static_cast<int A::*>(pc);
}
More information about the cfe-commits
mailing list