[llvm] 918015c - [EarlyCSE] Support opaque pointers
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 6 08:08:59 PST 2022
Author: Nikita Popov
Date: 2022-01-06T17:08:50+01:00
New Revision: 918015c9ba1a7e416a2844a862d412de57d1e427
URL: https://github.com/llvm/llvm-project/commit/918015c9ba1a7e416a2844a862d412de57d1e427
DIFF: https://github.com/llvm/llvm-project/commit/918015c9ba1a7e416a2844a862d412de57d1e427.diff
LOG: [EarlyCSE] Support opaque pointers
Explicitly check the load/store value type, because this is no
longer implicitly checked through the pointer type.
Added:
llvm/test/Transforms/EarlyCSE/opaque-ptr.ll
Modified:
llvm/lib/Transforms/Scalar/EarlyCSE.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index a24997dd3fd4a..59b934c16c8a0 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -827,10 +827,13 @@ class EarlyCSE {
const ParseMemoryInst &Later);
Value *getOrCreateResult(Value *Inst, Type *ExpectedType) const {
+ // TODO: We could insert relevant casts on type mismatch here.
if (auto *LI = dyn_cast<LoadInst>(Inst))
- return LI;
- if (auto *SI = dyn_cast<StoreInst>(Inst))
- return SI->getValueOperand();
+ return LI->getType() == ExpectedType ? LI : nullptr;
+ else if (auto *SI = dyn_cast<StoreInst>(Inst)) {
+ Value *V = SI->getValueOperand();
+ return V->getType() == ExpectedType ? V : nullptr;
+ }
assert(isa<IntrinsicInst>(Inst) && "Instruction not supported");
auto *II = cast<IntrinsicInst>(Inst);
if (isHandledNonTargetIntrinsic(II->getIntrinsicID()))
diff --git a/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll b/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll
new file mode 100644
index 0000000000000..bc278feb4ae88
--- /dev/null
+++ b/llvm/test/Transforms/EarlyCSE/opaque-ptr.ll
@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -early-cse -opaque-pointers < %s | FileCheck %s
+
+define i32 @
diff erent_types_load(ptr %p) {
+; CHECK-LABEL: @
diff erent_types_load(
+; CHECK-NEXT: [[V1:%.*]] = load i32, ptr [[P:%.*]], align 4
+; CHECK-NEXT: [[V2:%.*]] = load i64, ptr [[P]], align 4
+; CHECK-NEXT: [[V2_C:%.*]] = trunc i64 [[V2]] to i32
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[V1]], [[V2_C]]
+; CHECK-NEXT: ret i32 [[SUB]]
+;
+ %v1 = load i32, ptr %p
+ %v2 = load i64, ptr %p
+ %v2.c = trunc i64 %v2 to i32
+ %sub = sub i32 %v1, %v2.c
+ ret i32 %sub
+}
+
+define i32 @
diff erent_types_store(ptr %p, i32 %a) {
+; CHECK-LABEL: @
diff erent_types_store(
+; CHECK-NEXT: store i32 [[A:%.*]], ptr [[P:%.*]], align 4
+; CHECK-NEXT: [[V2:%.*]] = load i64, ptr [[P]], align 4
+; CHECK-NEXT: [[V2_C:%.*]] = trunc i64 [[V2]] to i32
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[A]], [[V2_C]]
+; CHECK-NEXT: ret i32 [[SUB]]
+;
+ store i32 %a, ptr %p
+ %v2 = load i64, ptr %p
+ %v2.c = trunc i64 %v2 to i32
+ %sub = sub i32 %a, %v2.c
+ ret i32 %sub
+}
More information about the llvm-commits
mailing list