[PATCH] D130672: [llvm] Extend the CaptureTracking to handle constantExprs that read global variables
Ruobing Han via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 27 16:26:25 PDT 2022
drcut created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
drcut requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This patch can optimize dead store which cannot be optimized due to the conservative capture tracking which does not concern Constant Expression
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130672
Files:
llvm/lib/Analysis/CaptureTracking.cpp
llvm/test/Transforms/DeadStoreElimination/const-expr.ll
Index: llvm/test/Transforms/DeadStoreElimination/const-expr.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/DeadStoreElimination/const-expr.ll
@@ -0,0 +1,18 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=dse -S < %s | FileCheck %s
+ at global = external constant [4 x i8]
+
+define internal void @f() {
+; CHECK-LABEL: @f(
+; CHECK-NEXT: [[TMP1:%.*]] = call noalias i8* @_Znwm(i64 32)
+; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i8* [[TMP1]], getelementptr inbounds ([4 x i8], [4 x i8]* @global, i64 0, i64 0)
+; CHECK-NEXT: ret void
+;
+ %tmp1 = call noalias i8* @_Znwm(i64 32)
+ %tmp2 = icmp ugt i8* %tmp1, getelementptr inbounds ([4 x i8], [4 x i8]* @global, i64 0, i64 0)
+ %tmp3 = getelementptr inbounds i8, i8* %tmp1, i64 3
+ store i8 0, i8* %tmp3
+ ret void
+}
+
+declare i8* @_Znwm(i64)
Index: llvm/lib/Analysis/CaptureTracking.cpp
===================================================================
--- llvm/lib/Analysis/CaptureTracking.cpp
+++ llvm/lib/Analysis/CaptureTracking.cpp
@@ -424,6 +424,11 @@
auto *LI = dyn_cast<LoadInst>(I->getOperand(OtherIdx));
if (LI && isa<GlobalVariable>(LI->getPointerOperand()))
return UseCaptureKind::NO_CAPTURE;
+ if (auto *CE = dyn_cast<ConstantExpr>(I->getOperand(OtherIdx))) {
+ if (CE->getOpcode() == Instruction::GetElementPtr &&
+ isa<GlobalVariable>(CE->getOperand(0)))
+ return UseCaptureKind::NO_CAPTURE;
+ }
// Otherwise, be conservative. There are crazy ways to capture pointers
// using comparisons.
return UseCaptureKind::MAY_CAPTURE;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130672.448206.patch
Type: text/x-patch
Size: 1674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220727/d7859111/attachment.bin>
More information about the llvm-commits
mailing list