From 3bdfa966ecd2a0c9b938f4c1e297000dbbb4a9b2 Mon Sep 17 00:00:00 2001 From: Tyker Date: Tue, 14 Apr 2020 11:57:19 +0200 Subject: [PATCH] [AssumeBundles] preserve knowledge in DCE Reviewers: jdoerfert Reviewed By: jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77403 --- llvm/lib/Transforms/Scalar/DCE.cpp | 2 ++ llvm/test/Transforms/DCE/basic-preservation.ll | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 llvm/test/Transforms/DCE/basic-preservation.ll diff --git a/llvm/lib/Transforms/Scalar/DCE.cpp b/llvm/lib/Transforms/Scalar/DCE.cpp index a4b0c8df98f6..28947482e303 100644 --- a/llvm/lib/Transforms/Scalar/DCE.cpp +++ b/llvm/lib/Transforms/Scalar/DCE.cpp @@ -25,6 +25,7 @@ #include "llvm/Pass.h" #include "llvm/Support/DebugCounter.h" #include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Utils/AssumeBundleBuilder.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/Local.h" using namespace llvm; @@ -127,6 +128,7 @@ static bool DCEInstruction(Instruction *I, return false; salvageDebugInfo(*I); + salvageKnowledge(I); // Null out all of the instruction's operands to see if any operand becomes // dead as we go. diff --git a/llvm/test/Transforms/DCE/basic-preservation.ll b/llvm/test/Transforms/DCE/basic-preservation.ll new file mode 100644 index 000000000000..173236cdc4a0 --- /dev/null +++ b/llvm/test/Transforms/DCE/basic-preservation.ll @@ -0,0 +1,11 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -dce -S --enable-knowledge-retention < %s | FileCheck %s + +define void @test(i32* %P) { +; CHECK-LABEL: @test( +; CHECK-NEXT: call void @llvm.assume(i1 true) [ "dereferenceable"(i32* [[P:%.*]], i64 4), "nonnull"(i32* [[P]]) ] +; CHECK-NEXT: ret void +; + %a = load i32, i32* %P + ret void +}