[PATCH] D66338: [CGP] Drop llvm.assume calls
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 02:58:04 PDT 2019
xbolva00 created this revision.
xbolva00 added reviewers: jdoerfert, craig.topper.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If llvm.assume expression contains side effect, Clang doesn't codegen such llvm.assume. Otherwise, if the expr is "pure/const", it may survive the whole middlend pipeline.
The problem: AFAIK llvm.assume calls are not propagated to backend. This means the backend just drops it, but fails to eliminate dead instructions related to llvm.assumes.
Should fix PR43007 and partially 43010 too.
Repository:
rL LLVM
https://reviews.llvm.org/D66338
Files:
lib/CodeGen/CodeGenPrepare.cpp
test/Transforms/CodeGenPrepare/assume.ll
Index: test/Transforms/CodeGenPrepare/assume.ll
===================================================================
--- test/Transforms/CodeGenPrepare/assume.ll
+++ test/Transforms/CodeGenPrepare/assume.ll
@@ -0,0 +1,17 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -codegenprepare -S %s | FileCheck %s
+
+declare i32 @foo()
+declare void @llvm.assume(i1)
+
+define void @bar() {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT: ret void
+;
+ %call = tail call i32 @foo() #0
+ %cmp = icmp eq i32 %call, 1
+ tail call void @llvm.assume(i1 %cmp)
+ ret void
+}
+
+attributes #0 = { nounwind readnone }
Index: lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- lib/CodeGen/CodeGenPrepare.cpp
+++ lib/CodeGen/CodeGenPrepare.cpp
@@ -6926,6 +6926,12 @@
if (InsertedInsts.count(I))
return false;
+ // Drop all llvm.assume calls
+ if (match(I, m_Intrinsic<Intrinsic::assume>())) {
+ RecursivelyDeleteTriviallyDeadInstructions(I);
+ return true;
+ }
+
// TODO: Move into the switch on opcode below here.
if (PHINode *P = dyn_cast<PHINode>(I)) {
// It is possible for very late stage optimizations (such as SimplifyCFG)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66338.215552.patch
Type: text/x-patch
Size: 1231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190816/3c64246c/attachment.bin>
More information about the llvm-commits
mailing list