[llvm] 5d63903 - [SCCP] Check that load/store and global type match
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 02:01:26 PST 2022
Author: Nikita Popov
Date: 2022-02-11T11:01:18+01:00
New Revision: 5d639034652dda9659e45ffd863e5052ab8ffc4a
URL: https://github.com/llvm/llvm-project/commit/5d639034652dda9659e45ffd863e5052ab8ffc4a
DIFF: https://github.com/llvm/llvm-project/commit/5d639034652dda9659e45ffd863e5052ab8ffc4a.diff
LOG: [SCCP] Check that load/store and global type match
SCCP requires that the load/store type and global type are the
same (it does not support bitcasts of tracked globals). With
typed pointers this was implicitly enforced.
Added:
llvm/test/Transforms/SCCP/opaque-ptr.ll
Modified:
llvm/lib/Analysis/ValueLatticeUtils.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueLatticeUtils.cpp b/llvm/lib/Analysis/ValueLatticeUtils.cpp
index 53638c351f722..2bcb4d5b0e6b1 100644
--- a/llvm/lib/Analysis/ValueLatticeUtils.cpp
+++ b/llvm/lib/Analysis/ValueLatticeUtils.cpp
@@ -29,12 +29,13 @@ bool llvm::canTrackGlobalVariableInterprocedurally(GlobalVariable *GV) {
!GV->hasDefinitiveInitializer())
return false;
return all_of(GV->users(), [&](User *U) {
- // Currently all users of a global variable have to be none-volatile loads
- // or stores and the global cannot be stored itself.
+ // Currently all users of a global variable have to be non-volatile loads
+ // or stores of the global type, and the global cannot be stored itself.
if (auto *Store = dyn_cast<StoreInst>(U))
- return Store->getValueOperand() != GV && !Store->isVolatile();
+ return Store->getValueOperand() != GV && !Store->isVolatile() &&
+ Store->getValueOperand()->getType() == GV->getValueType();
if (auto *Load = dyn_cast<LoadInst>(U))
- return !Load->isVolatile();
+ return !Load->isVolatile() && Load->getType() == GV->getValueType();
return false;
});
diff --git a/llvm/test/Transforms/SCCP/opaque-ptr.ll b/llvm/test/Transforms/SCCP/opaque-ptr.ll
new file mode 100644
index 0000000000000..9306ec397cf0e
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/opaque-ptr.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -ipsccp -opaque-pointers < %s | FileCheck %s
+
+ at g1 = internal global i32 1
+ at g2 = internal global i32 1
+
+define i8 @test1() {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT: [[V:%.*]] = load i8, ptr @g1, align 1
+; CHECK-NEXT: ret i8 [[V]]
+;
+ %v = load i8, ptr @g1
+ ret i8 %v
+}
+
+define void @test2() {
+; CHECK-LABEL: @test2(
+; CHECK-NEXT: store i8 2, ptr @g2, align 1
+; CHECK-NEXT: ret void
+;
+ store i8 2, ptr @g2
+ ret void
+}
More information about the llvm-commits
mailing list