[llvm] 52cc97a - [CodeGenPrepare] Zap the argument of llvm.assume when deleting it
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 11:52:37 PDT 2020
Author: Benjamin Kramer
Date: 2020-08-28T20:52:22+02:00
New Revision: 52cc97a0db2d4c20655d4df7f2ae5c087ee5807b
URL: https://github.com/llvm/llvm-project/commit/52cc97a0db2d4c20655d4df7f2ae5c087ee5807b
DIFF: https://github.com/llvm/llvm-project/commit/52cc97a0db2d4c20655d4df7f2ae5c087ee5807b.diff
LOG: [CodeGenPrepare] Zap the argument of llvm.assume when deleting it
We know that the argument is mostly likely dead, so we can purge it
early. Otherwise it would make it to codegen, and can block further
optimizations.
Added:
llvm/test/Transforms/CodeGenPrepare/X86/delete-assume-dead-code.ll
Modified:
llvm/lib/CodeGen/CodeGenPrepare.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 2034fd0730eb..3272f36a1436 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2044,7 +2044,12 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool &ModifiedDT) {
switch (II->getIntrinsicID()) {
default: break;
case Intrinsic::assume: {
+ Value *Operand = II->getOperand(0);
II->eraseFromParent();
+ // Prune the operand, it's most likely dead.
+ RecursivelyDeleteTriviallyDeadInstructions(
+ Operand, TLInfo, nullptr,
+ [&](Value *V) { removeAllAssertingVHReferences(V); });
return true;
}
diff --git a/llvm/test/Transforms/CodeGenPrepare/X86/delete-assume-dead-code.ll b/llvm/test/Transforms/CodeGenPrepare/X86/delete-assume-dead-code.ll
new file mode 100644
index 000000000000..17e46b614609
--- /dev/null
+++ b/llvm/test/Transforms/CodeGenPrepare/X86/delete-assume-dead-code.ll
@@ -0,0 +1,35 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -codegenprepare -S -mtriple=x86_64-linux < %s | FileCheck %s
+
+define i32 @test1(i8* %d) nounwind {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[L:%.*]] = load i8, i8* [[D:%.*]], align 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[L]], 0
+; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[IF_END:%.*]]
+; CHECK: if.end:
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i8 [[L]], 0
+; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[TMP0]] to i32
+; CHECK-NEXT: ret i32 [[CONV]]
+;
+entry:
+ %l = load i8, i8* %d
+ %cmp = icmp eq i8 %l, 0
+ br i1 %cmp, label %exit, label %if.end
+
+if.end:
+ %gep = getelementptr i8, i8* %d, i32 42
+ %call = call i64 @foo(i8* %gep) nounwind readonly
+ %cmp2 = icmp ne i64 %call, 0
+ call void @llvm.assume(i1 %cmp2)
+ br label %exit
+
+exit:
+ %conv = zext i1 %cmp to i32
+ ret i32 %conv
+}
+
+declare i64 @foo(i8*) nounwind readonly
+declare void @llvm.assume(i1 noundef) nounwind willreturn
More information about the llvm-commits
mailing list