[llvm-commits] [dragonegg] r95210 - in /dragonegg/trunk: llvm-convert.cpp llvm-internal.h
Duncan Sands
baldrick at free.fr
Wed Feb 3 00:42:17 PST 2010
Author: baldrick
Date: Wed Feb 3 02:42:16 2010
New Revision: 95210
URL: http://llvm.org/viewvc/llvm-project?rev=95210&view=rev
Log:
Clean negation code - make use of NSW/NUW flags.
Modified:
dragonegg/trunk/llvm-convert.cpp
dragonegg/trunk/llvm-internal.h
Modified: dragonegg/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-convert.cpp?rev=95210&r1=95209&r2=95210&view=diff
==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Wed Feb 3 02:42:16 2010
@@ -1360,6 +1360,18 @@
return Builder.CreateNSWMul(LHS, RHS);
}
+/// CreateAnyNeg - Negate an LLVM scalar value with the given GCC type. Does
+/// not support complex numbers. The type is used to set overflow flags.
+Value *TreeToLLVM::CreateAnyNeg(Value *V, tree_node *type) {
+ if (FLOAT_TYPE_P(type))
+ return Builder.CreateFNeg(V);
+ if (TYPE_OVERFLOW_WRAPS(type))
+ return Builder.CreateNeg(V);
+ if (TYPE_UNSIGNED(type))
+ return Builder.CreateNUWNeg(V);
+ return Builder.CreateNSWNeg(V);
+}
+
/// CreateAnySub - Subtract two LLVM scalar values with the given GCC type.
/// Does not support complex numbers. The type is used to set overflow flags.
Value *TreeToLLVM::CreateAnySub(Value *LHS, Value *RHS, tree_node *type) {
@@ -5911,14 +5923,14 @@
}
Value *TreeToLLVM::EmitReg_CONJ_EXPR(tree op) {
- // ~(a+ib) = a + i*-b
+ tree elt_type = TREE_TYPE(TREE_TYPE(op));
Value *R, *I;
- SplitComplex(EmitRegister(op), R, I, TREE_TYPE(TREE_TYPE(op)));
- if (I->getType()->isFloatingPoint())
- I = Builder.CreateFNeg(I);
- else
- I = Builder.CreateNeg(I);
- return CreateComplex(R, I, TREE_TYPE(TREE_TYPE(op)));
+ SplitComplex(EmitRegister(op), R, I, elt_type);
+
+ // ~(a+ib) = a + i*-b
+ I = CreateAnyNeg(I, elt_type);
+
+ return CreateComplex(R, I, elt_type);
}
Value *TreeToLLVM::EmitReg_CONVERT_EXPR(tree type, tree op) {
@@ -5928,25 +5940,20 @@
Value *TreeToLLVM::EmitReg_NEGATE_EXPR(tree op) {
Value *V = EmitRegister(op);
+ tree type = TREE_TYPE(op);
- if (TREE_CODE(TREE_TYPE(op)) != COMPLEX_TYPE) {
- if (V->getType()->isFPOrFPVector())
- return Builder.CreateFNeg(V);
- bool HasNSW = !TYPE_OVERFLOW_WRAPS(TREE_TYPE(op));
- return HasNSW ? Builder.CreateNSWNeg(V) : Builder.CreateNeg(V);
- }
+ if (TREE_CODE(type) == COMPLEX_TYPE) {
+ tree elt_type = TREE_TYPE(type);
+ Value *R, *I; SplitComplex(V, R, I, elt_type);
- // -(a+ib) = -a + i*-b
- Value *R, *I;
- SplitComplex(V, R, I, TREE_TYPE(TREE_TYPE(op)));
- if (R->getType()->isFloatingPoint()) {
- R = Builder.CreateFNeg(R);
- I = Builder.CreateFNeg(I);
- } else {
- R = Builder.CreateNeg(R);
- I = Builder.CreateNeg(I);
+ // -(a+ib) = -a + i*-b
+ R = CreateAnyNeg(R, elt_type);
+ I = CreateAnyNeg(I, elt_type);
+
+ return CreateComplex(R, I, elt_type);
}
- return CreateComplex(R, I, TREE_TYPE(TREE_TYPE(op)));
+
+ return CreateAnyNeg(V, type);
}
Value *TreeToLLVM::EmitReg_PAREN_EXPR(tree op) {
Modified: dragonegg/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-internal.h?rev=95210&r1=95209&r2=95210&view=diff
==============================================================================
--- dragonegg/trunk/llvm-internal.h (original)
+++ dragonegg/trunk/llvm-internal.h Wed Feb 3 02:42:16 2010
@@ -481,6 +481,10 @@
/// Does not support complex numbers. The type is used to set overflow flags.
Value *CreateAnyMul(Value *LHS, Value *RHS, tree_node *type);
+ /// CreateAnyNeg - Negate an LLVM scalar value with the given GCC type. Does
+ /// not support complex numbers. The type is used to set overflow flags.
+ Value *CreateAnyNeg(Value *V, tree_node *type);
+
/// CreateAnySub - Subtract two LLVM scalar values with the given GCC type.
/// Does not support complex numbers.
Value *CreateAnySub(Value *LHS, Value *RHS, tree_node *type);
More information about the llvm-commits
mailing list