[llvm-commits] CVS: llvm/lib/Analysis/ConstantFolding.cpp
Reid Spencer
reid at x10sys.com
Sun Apr 1 00:35:45 PDT 2007
Changes in directory llvm/lib/Analysis:
ConstantFolding.cpp updated: 1.20 -> 1.21
---
Log message:
For PR1297: http://llvm.org/PR1297 :
Support overloaded intrinsics bswap, ctpop, cttz, ctlz.
---
Diffs of the changes: (+17 -23)
ConstantFolding.cpp | 40 +++++++++++++++++-----------------------
1 files changed, 17 insertions(+), 23 deletions(-)
Index: llvm/lib/Analysis/ConstantFolding.cpp
diff -u llvm/lib/Analysis/ConstantFolding.cpp:1.20 llvm/lib/Analysis/ConstantFolding.cpp:1.21
--- llvm/lib/Analysis/ConstantFolding.cpp:1.20 Sun Mar 4 18:00:41 2007
+++ llvm/lib/Analysis/ConstantFolding.cpp Sun Apr 1 02:35:23 2007
@@ -317,24 +317,12 @@
switch (F->getIntrinsicID()) {
case Intrinsic::sqrt_f32:
case Intrinsic::sqrt_f64:
- case Intrinsic::bswap_i16:
- case Intrinsic::bswap_i32:
- case Intrinsic::bswap_i64:
case Intrinsic::powi_f32:
case Intrinsic::powi_f64:
- // FIXME: these should be constant folded as well
- //case Intrinsic::ctpop_i8:
- //case Intrinsic::ctpop_i16:
- //case Intrinsic::ctpop_i32:
- //case Intrinsic::ctpop_i64:
- //case Intrinsic::ctlz_i8:
- //case Intrinsic::ctlz_i16:
- //case Intrinsic::ctlz_i32:
- //case Intrinsic::ctlz_i64:
- //case Intrinsic::cttz_i8:
- //case Intrinsic::cttz_i16:
- //case Intrinsic::cttz_i32:
- //case Intrinsic::cttz_i64:
+ case Intrinsic::bswap:
+ case Intrinsic::ctpop:
+ case Intrinsic::ctlz:
+ case Intrinsic::cttz:
return true;
default: break;
}
@@ -445,13 +433,19 @@
break;
}
} else if (ConstantInt *Op = dyn_cast<ConstantInt>(Operands[0])) {
- uint64_t V = Op->getZExtValue();
- if (Name == "llvm.bswap.i16")
- return ConstantInt::get(Ty, ByteSwap_16(V));
- else if (Name == "llvm.bswap.i32")
- return ConstantInt::get(Ty, ByteSwap_32(V));
- else if (Name == "llvm.bswap.i64")
- return ConstantInt::get(Ty, ByteSwap_64(V));
+ const IntegerType *OpTy = cast<IntegerType>(Op->getType());
+ if (Name.size() > 11 && !memcmp(&Name[0], "llvm.bswap", 10)) {
+ return ConstantInt::get(Op->getValue().byteSwap());
+ } else if (Name.size() > 11 && !memcmp(&Name[0],"llvm.ctpop",10)) {
+ uint64_t ctpop = Op->getValue().countPopulation();
+ return ConstantInt::get(OpTy, ctpop);
+ } else if (Name.size() > 10 && !memcmp(&Name[0], "llvm.cttz", 9)) {
+ uint64_t cttz = Op->getValue().countTrailingZeros();
+ return ConstantInt::get(OpTy, cttz);
+ } else if (Name.size() > 10 && !memcmp(&Name[0], "llvm.ctlz", 9)) {
+ uint64_t ctlz = Op->getValue().countLeadingZeros();
+ return ConstantInt::get(OpTy, ctlz);
+ }
}
} else if (NumOperands == 2) {
if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
More information about the llvm-commits
mailing list