[llvm] 7ce98cf - [GlobalOpt] Fix the assert for stored once non-pointer to global address

Shimin Cui via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 2 16:24:14 PDT 2021


Author: Shimin Cui
Date: 2021-08-02T19:23:29-04:00
New Revision: 7ce98cf56e3ea9c8dd8d55f6f61b1bed9de4c70a

URL: https://github.com/llvm/llvm-project/commit/7ce98cf56e3ea9c8dd8d55f6f61b1bed9de4c70a
DIFF: https://github.com/llvm/llvm-project/commit/7ce98cf56e3ea9c8dd8d55f6f61b1bed9de4c70a.diff

LOG: [GlobalOpt] Fix the assert for stored once non-pointer to global address

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.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D107302

Added: 
    llvm/test/Transforms/GlobalOpt/2021-08-02-CastStoreOnceP2I.ll

Modified: 
    llvm/lib/Transforms/IPO/GlobalOpt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 8aa7e015982f0..94cd56f1e8e37 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1161,6 +1161,7 @@ optimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
   // value was null.
   if (GV->getInitializer()->getType()->isPointerTy() &&
       GV->getInitializer()->isNullValue() &&
+      StoredOnceVal->getType()->isPointerTy() &&
       !NullPointerIsDefined(
           nullptr /* F */,
           GV->getInitializer()->getType()->getPointerAddressSpace())) {

diff  --git a/llvm/test/Transforms/GlobalOpt/2021-08-02-CastStoreOnceP2I.ll b/llvm/test/Transforms/GlobalOpt/2021-08-02-CastStoreOnceP2I.ll
new file mode 100644
index 0000000000000..a54186b0aa7a5
--- /dev/null
+++ b/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
+}


        


More information about the llvm-commits mailing list