diff options
-rw-r--r-- | llvm/include/llvm/IR/Constant.h | 3 | ||||
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 6 | ||||
-rw-r--r-- | llvm/test/Transforms/SCCP/apint-bigint2.ll | 20 |
3 files changed, 23 insertions, 6 deletions
diff --git a/llvm/include/llvm/IR/Constant.h b/llvm/include/llvm/IR/Constant.h index 5fdf0ea..98437f8 100644 --- a/llvm/include/llvm/IR/Constant.h +++ b/llvm/include/llvm/IR/Constant.h @@ -114,7 +114,8 @@ public: /// For aggregates (struct/array/vector) return the constant that corresponds /// to the specified element if possible, or null if not. This can return null - /// if the element index is a ConstantExpr, or if 'this' is a constant expr. + /// if the element index is a ConstantExpr, if 'this' is a constant expr or + /// if the constant does not fit into an uint64_t. Constant *getAggregateElement(unsigned Elt) const; Constant *getAggregateElement(Constant *Elt) const; diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 22ffc811..df09d13 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -350,8 +350,12 @@ Constant *Constant::getAggregateElement(unsigned Elt) const { Constant *Constant::getAggregateElement(Constant *Elt) const { assert(isa<IntegerType>(Elt->getType()) && "Index must be an integer"); - if (ConstantInt *CI = dyn_cast<ConstantInt>(Elt)) + if (ConstantInt *CI = dyn_cast<ConstantInt>(Elt)) { + // Check if the constant fits into an uint64_t. + if (CI->getValue().getActiveBits() > 64) + return nullptr; return getAggregateElement(CI->getZExtValue()); + } return nullptr; } diff --git a/llvm/test/Transforms/SCCP/apint-bigint2.ll b/llvm/test/Transforms/SCCP/apint-bigint2.ll index f28b966..20b54fed 100644 --- a/llvm/test/Transforms/SCCP/apint-bigint2.ll +++ b/llvm/test/Transforms/SCCP/apint-bigint2.ll @@ -1,11 +1,11 @@ -; RUN: opt < %s -sccp -S | not grep load +; RUN: opt < %s -sccp -S | FileCheck %s @Y = constant [6 x i101] [ i101 12, i101 123456789000000, i101 -12, i101 -123456789000000, i101 0,i101 9123456789000000] -define i101 @array() -{ -Head: +; CHECK-LABEL: @array +; CHECK-NEXT: ret i101 123456789000000 +define i101 @array() { %A = getelementptr [6 x i101], [6 x i101]* @Y, i32 0, i32 1 %B = load i101, i101* %A %D = and i101 %B, 1 @@ -16,3 +16,15 @@ Head: ret i101 %G } + +; CHECK-LABEL: @large_aggregate +; CHECK-NEXT: ret i101 undef +define i101 @large_aggregate() { + %B = load i101, i101* undef + %D = and i101 %B, 1 + %DD = or i101 %D, 1 + %F = getelementptr [6 x i101], [6 x i101]* @Y, i32 0, i32 5 + %G = getelementptr i101, i101* %F, i101 %DD + %L3 = load i101, i101* %G + ret i101 %L3 +} |