[PATCH] D107302: [GlobalOpt] Fix the assert for stored once non-pointer to global address
Shimin Cui via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 2 12:29:04 PDT 2021
scui created this revision.
scui added reviewers: bjope, efriedma.
Herald added subscribers: ormris, hiraditya.
scui requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is to fix the assert @bjope reported due to the code change of https://reviews.llvm.org/D106589. The test case from @bjope is also included.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107302
Files:
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/test/Transforms/GlobalOpt/2021-08-02-CastStoreOnceP2I.ll
Index: llvm/test/Transforms/GlobalOpt/2021-08-02-CastStoreOnceP2I.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GlobalOpt/2021-08-02-CastStoreOnceP2I.ll
@@ -0,0 +1,20 @@
+; RUN: opt -globalopt -S < %s | FileCheck %s
+; RUN: opt -passes=globalopt -S < %s | FileCheck %s
+
+; This tests the assignemnt of non-pointer to global address
+; (assert due to D106589).
+
+ at a162 = internal global i16* null, align 1
+
+define void @f363() {
+; CHECK-LABEL: @f363(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = load i16*, i16** @a162, align 1
+; CHECK-NEXT: store i16 0, i16* bitcast (i16** @a162 to i16*), align 1
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = load i16*, i16** @a162, align 1
+ store i16 0, i16* bitcast (i16** @a162 to i16*), align 1
+ ret void
+}
Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1161,6 +1161,7 @@
// value was null.
if (GV->getInitializer()->getType()->isPointerTy() &&
GV->getInitializer()->isNullValue() &&
+ StoredOnceVal->getType()->isPointerTy() &&
!NullPointerIsDefined(
nullptr /* F */,
GV->getInitializer()->getType()->getPointerAddressSpace())) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107302.363544.patch
Type: text/x-patch
Size: 1360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210802/ec10b521/attachment.bin>
More information about the llvm-commits
mailing list