[PATCH] D124241: [Local] Consider atomic loads from constant global as dead
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 2 01:53:18 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaae5f8115a7c: [Local] Consider atomic loads from constant global as dead (authored by nikic).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124241/new/
https://reviews.llvm.org/D124241
Files:
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/CodeGen/PowerPC/atomics-constant.ll
llvm/test/Transforms/InstCombine/atomic.ll
Index: llvm/test/Transforms/InstCombine/atomic.ll
===================================================================
--- llvm/test/Transforms/InstCombine/atomic.ll
+++ llvm/test/Transforms/InstCombine/atomic.ll
@@ -426,7 +426,6 @@
define i32 @atomic_load_from_constant_global() {
; CHECK-LABEL: @atomic_load_from_constant_global(
-; CHECK-NEXT: [[V:%.*]] = load atomic i32, i32* @c seq_cst, align 4
; CHECK-NEXT: ret i32 42
;
%v = load atomic i32, i32* @c seq_cst, align 4
@@ -435,7 +434,6 @@
define i8 @atomic_load_from_constant_global_bitcast() {
; CHECK-LABEL: @atomic_load_from_constant_global_bitcast(
-; CHECK-NEXT: [[V:%.*]] = load atomic i8, i8* bitcast (i32* @c to i8*) seq_cst, align 1
; CHECK-NEXT: ret i8 42
;
%v = load atomic i8, i8* bitcast (i32* @c to i8*) seq_cst, align 1
Index: llvm/test/CodeGen/PowerPC/atomics-constant.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/atomics-constant.ll
+++ llvm/test/CodeGen/PowerPC/atomics-constant.ll
@@ -3,16 +3,14 @@
target triple = "powerpc64le-unknown-linux-gnu"
- at a = dso_local constant i64 zeroinitializer
+ at a = dso_local global i64 zeroinitializer
define i64 @foo() {
; CHECK-LABEL: foo:
; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: li 4, 0
; CHECK-NEXT: addis 3, 2, a at toc@ha
; CHECK-NEXT: ld 3, a at toc@l(3)
-; CHECK-NEXT: cmpd 7, 4, 4
-; CHECK-NEXT: li 3, 0
+; CHECK-NEXT: cmpd 7, 3, 3
; CHECK-NEXT: bne- 7, .+4
; CHECK-NEXT: isync
; CHECK-NEXT: blr
Index: llvm/lib/Transforms/Utils/Local.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Local.cpp
+++ llvm/lib/Transforms/Utils/Local.cpp
@@ -500,6 +500,13 @@
if (isMathLibCallNoop(Call, TLI))
return true;
+ // Non-volatile atomic loads from constants can be removed.
+ if (auto *LI = dyn_cast<LoadInst>(I))
+ if (auto *GV = dyn_cast<GlobalVariable>(
+ LI->getPointerOperand()->stripPointerCasts()))
+ if (!LI->isVolatile() && GV->isConstant())
+ return true;
+
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124241.426358.patch
Type: text/x-patch
Size: 2121 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220502/40d1237d/attachment.bin>
More information about the llvm-commits
mailing list