[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c llvm-representation.h llvm-types.c
Chris Lattner
lattner at cs.uiuc.edu
Mon Jan 16 22:22:34 PST 2006
Changes in directory llvm-gcc/gcc:
llvm-expand.c updated: 1.125 -> 1.126
llvm-representation.h updated: 1.22 -> 1.23
llvm-types.c updated: 1.31 -> 1.32
---
Log message:
Force bit count intrinsics to all have unsigned operands and unsigned results.
---
Diffs of the changes: (+70 -45)
llvm-expand.c | 101 ++++++++++++++++++++++++++++----------------------
llvm-representation.h | 3 -
llvm-types.c | 11 +++++
3 files changed, 70 insertions(+), 45 deletions(-)
Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.125 llvm-gcc/gcc/llvm-expand.c:1.126
--- llvm-gcc/gcc/llvm-expand.c:1.125 Mon Jan 16 16:21:14 2006
+++ llvm-gcc/gcc/llvm-expand.c Tue Jan 17 00:22:23 2006
@@ -3394,7 +3394,7 @@
/* Add a PHI node to merge together the two computed values */
- if (CondBr->NumOperands == 1 && CondBr->Operands[0] != DoneBlock) {
+ if (CondBr->NumOperands == 1 && CondBr->Operands[0] != D2V(DoneBlock)) {
/* The cond branch terminating FromBlock was folded to not go to the done
* block at all. This code is only reachable from the TestBlock.
*/
@@ -4585,19 +4585,23 @@
return BL->Fn = CreateIntrinsicFnWithType(Name, FnTy);
}
-static llvm_value *
-llvm_expand_builtin_unaryop(llvm_function *Fn, llvm_type *DestTy,
- tree arglist, const char *FnName) {
- llvm_value *arg;
- llvm_instruction *TheCall;
+/* llvm_expand_unaryop - Expand the specified operand list to a unary function,
+ * checking that it is actually a list with one element.
+ */
+static llvm_value *llvm_expand_unaryop(llvm_function *Fn, tree arglist) {
if (arglist == 0 || TREE_CHAIN(arglist) != 0) {
- error("Invalid argument list to `%s'", FnName);
- return llvm_constant_get_null(DestTy);
+ error("Invalid argument list to function");
+ exit(1);
}
-
- arg = llvm_expand_expr(Fn, TREE_VALUE(arglist), 0);
- TheCall = llvm_instruction_new(arg->Ty, "tmp", O_Call, 2);
+ return llvm_expand_expr(Fn, TREE_VALUE(arglist), 0);
+}
+
+static llvm_value *
+llvm_expand_builtin_unaryop(llvm_function *Fn, llvm_type *DestTy,
+ llvm_value *arg, const char *FnName) {
+ llvm_instruction *TheCall =
+ llvm_instruction_new(arg->Ty, "tmp", O_Call, 2);
TheCall->Operands[0] = G2V(GetUnaryBuiltin(FnName, arg->Ty));
TheCall->Operands[1] = arg;
append_inst(Fn, TheCall);
@@ -4759,12 +4763,12 @@
case BUILT_IN_SQRTL:
/* If errno math has been disabled, expand these to llvm.sqrt calls. */
if (!flag_errno_math) {
- Op0 = llvm_expand_expr(Fn, TREE_VALUE(arglist), 0);
+ Op0 = llvm_expand_unaryop(Fn, arglist);
switch (Op0->Ty->ID) {
case FloatTyID:
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist,"llvm.sqrt.f32");
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.sqrt.f32");
case DoubleTyID:
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist,"llvm.sqrt.f64");
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.sqrt.f64");
default:
abort(); /* shouldn't happen */
}
@@ -4949,50 +4953,59 @@
case BUILT_IN_CLZ:
case BUILT_IN_CLZL:
case BUILT_IN_CLZLL:
- Op0 = llvm_expand_expr(Fn, TREE_VALUE(arglist), 0);
+ Op0 = llvm_expand_unaryop(Fn, arglist);
+ if (llvm_type_is_signed(Op0->Ty))
+ Op0 = cast_if_type_not_equal(Fn, Op0,
+ llvm_type_get_unsigned_version(Op0->Ty));
switch (Op0->Ty->ID) {
- case UByteTyID: case SByteTyID: /* 8 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.ctlz.i8");
- case UShortTyID: case ShortTyID: /* 16 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.ctlz.i16");
- case UIntTyID: case IntTyID: /* 32 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.ctlz.i32");
- case ULongTyID: case LongTyID: /* 64 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.ctlz.i64");
+ case UByteTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.ctlz.i8");
+ case UShortTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.ctlz.i16");
+ case UIntTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.ctlz.i32");
+ case ULongTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.ctlz.i64");
default:
- abort(); /* this shouldn't happen? */
+ abort(); /* this shouldn't happen */
}
case BUILT_IN_CTZ:
case BUILT_IN_CTZL:
case BUILT_IN_CTZLL:
- Op0 = llvm_expand_expr(Fn, TREE_VALUE(arglist), 0);
+ Op0 = llvm_expand_unaryop(Fn, arglist);
+ if (llvm_type_is_signed(Op0->Ty))
+ Op0 = cast_if_type_not_equal(Fn, Op0,
+ llvm_type_get_unsigned_version(Op0->Ty));
switch (Op0->Ty->ID) {
- case UByteTyID: case SByteTyID: /* 8 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.cttz.i8");
- case UShortTyID: case ShortTyID: /* 16 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.cttz.i16");
- case UIntTyID: case IntTyID: /* 32 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.cttz.i32");
- case ULongTyID: case LongTyID: /* 64 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.cttz.i64");
+ case UByteTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.cttz.i8");
+ case UShortTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.cttz.i16");
+ case UIntTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.cttz.i32");
+ case ULongTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.cttz.i64");
default:
- abort(); /* this shouldn't happen? */
+ abort(); /* this shouldn't happen */
}
case BUILT_IN_POPCOUNT:
case BUILT_IN_POPCOUNTL:
case BUILT_IN_POPCOUNTLL:
- Op0 = llvm_expand_expr(Fn, TREE_VALUE(arglist), 0);
+ Op0 = llvm_expand_unaryop(Fn, arglist);
+ if (llvm_type_is_signed(Op0->Ty))
+ Op0 = cast_if_type_not_equal(Fn, Op0,
+ llvm_type_get_unsigned_version(Op0->Ty));
switch (Op0->Ty->ID) {
- case UByteTyID: case SByteTyID: /* 8 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.ctpop.i8");
- case UShortTyID: case ShortTyID: /* 16 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.ctpop.i16");
- case UIntTyID: case IntTyID: /* 32 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.ctpop.i32");
- case ULongTyID: case LongTyID: /* 64 bit types... */
- return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.ctpop.i64");
+ case UByteTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.ctpop.i8");
+ case UShortTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.ctpop.i16");
+ case UIntTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.ctpop.i32");
+ case ULongTyID:
+ return llvm_expand_builtin_unaryop(Fn, DestTy, Op0, "llvm.ctpop.i64");
default:
- abort(); /* this shouldn't happen? */
+ abort(); /* this shouldn't happen */
}
#if 0
Index: llvm-gcc/gcc/llvm-representation.h
diff -u llvm-gcc/gcc/llvm-representation.h:1.22 llvm-gcc/gcc/llvm-representation.h:1.23
--- llvm-gcc/gcc/llvm-representation.h:1.22 Fri Dec 16 16:17:33 2005
+++ llvm-gcc/gcc/llvm-representation.h Tue Jan 17 00:22:23 2006
@@ -472,7 +472,8 @@
* promoted type.
*/
llvm_type *llvm_type_get_promoted_type(llvm_type *Ty);
-
+llvm_type *llvm_type_get_unsigned_version(llvm_type *Ty);
+
/* Creation methods for types */
llvm_type *llvm_type_get_array(llvm_type *Ty, unsigned NumElements);
llvm_type *llvm_type_get_pointer(llvm_type *Ty);
Index: llvm-gcc/gcc/llvm-types.c
diff -u llvm-gcc/gcc/llvm-types.c:1.31 llvm-gcc/gcc/llvm-types.c:1.32
--- llvm-gcc/gcc/llvm-types.c:1.31 Fri Nov 4 00:18:30 2005
+++ llvm-gcc/gcc/llvm-types.c Tue Jan 17 00:22:23 2006
@@ -554,6 +554,17 @@
}
}
+llvm_type *llvm_type_get_unsigned_version(llvm_type *Ty) {
+ assert(llvm_type_is_signed(Ty));
+ switch (Ty->ID) {
+ default: abort();
+ case SByteTyID: return UByteTy;
+ case ShortTyID: return UShortTy;
+ case IntTyID: return UIntTy;
+ case LongTyID: return ULongTy;
+ }
+}
+
/* This function prints the type list in reverse order. If this causes a
problem due to stack depth at some point, we should change construction of
More information about the llvm-commits
mailing list