diff options
author | Arnaud A. de Grandmaison <arnaud.adegm@gmail.com> | 2013-03-22 08:25:01 +0000 |
---|---|---|
committer | Arnaud A. de Grandmaison <arnaud.adegm@gmail.com> | 2013-03-22 08:25:01 +0000 |
commit | f364bc63e71355a94ca1ef442e7e5af64973239d (patch) | |
tree | 4edb459905de7e6370ae14926a0437201e04e252 /llvm/lib/IR | |
parent | f1311dfce1d434c724cd6ec5c1cf13e268b23511 (diff) | |
download | bcm5719-llvm-f364bc63e71355a94ca1ef442e7e5af64973239d.tar.gz bcm5719-llvm-f364bc63e71355a94ca1ef442e7e5af64973239d.zip |
InstCombine: Improve the result bitvect type when folding (cmp pred (load (gep GV, i)) C) to a bit test.
The original code used i32, and i64 if legal. This introduced unneeded
casts when they aren't legal, or when the index variable i has another
type. In order of preference: try to use i's type; use the smallest
fitting legal type (using an added DataLayout method); default to i32.
A testcase checks that this works when the index gep operand is i16.
Patch by : Ahmed Bougacha <ahmed.bougacha@gmail.com>
Reviewed by : Duncan
llvm-svn: 177712
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r-- | llvm/lib/IR/DataLayout.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index 95966749127..ecd5216f20a 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -621,6 +621,13 @@ Type *DataLayout::getIntPtrType(Type *Ty) const { return IntTy; } +Type *DataLayout::getSmallestLegalIntType(LLVMContext &C, unsigned Width) const { + for (unsigned i = 0, e = (unsigned)LegalIntWidths.size(); i != e; ++i) + if (Width <= LegalIntWidths[i]) + return Type::getIntNTy(C, LegalIntWidths[i]); + return 0; +} + uint64_t DataLayout::getIndexedOffset(Type *ptrTy, ArrayRef<Value *> Indices) const { Type *Ty = ptrTy; |