[PATCH] D65970: [GlobalOpt] prevent crashing on wide integer types (PR42932)
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 05:43:37 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368437: [GlobalOpt] prevent crashing on large integer types (PR42932) (authored by spatel, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D65970?vs=214223&id=214367#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65970/new/
https://reviews.llvm.org/D65970
Files:
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
llvm/trunk/test/Transforms/GlobalOpt/large-int-crash.ll
Index: llvm/trunk/test/Transforms/GlobalOpt/large-int-crash.ll
===================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/large-int-crash.ll
+++ llvm/trunk/test/Transforms/GlobalOpt/large-int-crash.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+ at X = internal global i128 0
+
+define void @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT: [[T0_B:%.*]] = load i1, i1* @X
+; CHECK-NEXT: [[T0:%.*]] = select i1 [[T0_B]], i128 18446744073709551616, i128 0
+; CHECK-NEXT: ret void
+;
+ %t0 = load i128, i128* @X, align 8
+ ret void
+}
+
+define void @store() {
+; CHECK-LABEL: @store(
+; CHECK-NEXT: store i1 true, i1* @X
+; CHECK-NEXT: ret void
+;
+ store i128 18446744073709551616, i128* @X, align 8
+ ret void
+}
Index: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1643,10 +1643,12 @@
// instead of a select to synthesize the desired value.
bool IsOneZero = false;
bool EmitOneOrZero = true;
- if (ConstantInt *CI = dyn_cast<ConstantInt>(OtherVal)){
+ auto *CI = dyn_cast<ConstantInt>(OtherVal);
+ if (CI && CI->getValue().getActiveBits() <= 64) {
IsOneZero = InitVal->isNullValue() && CI->isOne();
- if (ConstantInt *CIInit = dyn_cast<ConstantInt>(GV->getInitializer())){
+ auto *CIInit = dyn_cast<ConstantInt>(GV->getInitializer());
+ if (CIInit && CIInit->getValue().getActiveBits() <= 64) {
uint64_t ValInit = CIInit->getZExtValue();
uint64_t ValOther = CI->getZExtValue();
uint64_t ValMinus = ValOther - ValInit;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65970.214367.patch
Type: text/x-patch
Size: 1793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190809/18acd716/attachment.bin>
More information about the llvm-commits
mailing list