[llvm-commits] [llvm-gcc-4.2] r68968 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Chris Lattner
sabre at nondot.org
Mon Apr 13 11:00:53 PDT 2009
Author: lattner
Date: Mon Apr 13 13:00:53 2009
New Revision: 68968
URL: http://llvm.org/viewvc/llvm-project?rev=68968&view=rev
Log:
fix TreeConstantToLLVM::ConvertINTEGER_CST to correctly handle
INTEGER_CST's that are 128-bits in size instead of silently
discarding the top bits. This allows us to compile:
__uint128_t test2() {
const __uint128_t c_zero = ~0;
return c_zero;
}
__uint128_t test1() {
const __uint128_t c_zero = 1234;
return c_zero;
}
into:
define i128 @test2() nounwind readnone {
entry:
ret i128 -1
}
define i128 @test1() nounwind readnone {
entry:
ret i128 1234
}
instead of:
define i128 @test2() nounwind readnone {
entry:
ret i128 18446744073709551615
}
define i128 @test1() nounwind readnone {
entry:
ret i128 1234
}
This fixes PR3975.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=68968&r1=68967&r2=68968&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Mon Apr 13 13:00:53 2009
@@ -6423,12 +6423,20 @@
}
Constant *TreeConstantToLLVM::ConvertINTEGER_CST(tree exp) {
- // Convert it to a uint64_t.
- uint64_t IntValue = getINTEGER_CSTVal(exp);
+ const IntegerType *Ty = cast<IntegerType>(ConvertType(TREE_TYPE(exp)));
+
+ // Handle i128 specially.
+ if (Ty->getPrimitiveSizeInBits() == 128) {
+ // GCC only supports i128 on 64-bit systems.
+ assert(HOST_BITS_PER_WIDE_INT == 64 &&
+ "i128 only supported on 64-bit system");
+ uint64_t Bits[] = { TREE_INT_CST_LOW(exp), TREE_INT_CST_HIGH(exp) };
+ return ConstantInt::get(APInt(128, 2, Bits));
+ }
// Build the value as a ulong constant, then constant fold it to the right
// type. This handles overflow and other things appropriately.
- const Type *Ty = ConvertType(TREE_TYPE(exp));
+ uint64_t IntValue = getINTEGER_CSTVal(exp);
ConstantInt *C = ConstantInt::get(Type::Int64Ty, IntValue);
// The destination type can be a pointer, integer or floating point
// so we need a generalized cast here
More information about the llvm-commits
mailing list