[PATCH] D12484: [JumpThreading] make jump threading respect convergent annotation.For example, if (cond) { ... } else { ... } convergent_call(); if (cond) { ... } else { ... }should not be optimized to if (cond) { ...
Xuetian Weng via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 30 14:09:42 PDT 2015
wengxt created this revision.
wengxt added reviewers: resistor, jingyue.
wengxt added a subscriber: llvm-commits.
......
convergent_call();
...
} else {
...
convergent_call();
...
}
Test Plan: test/Transforms/JumpThreading/basic.ll
http://reviews.llvm.org/D12484
Files:
include/llvm/IR/Instructions.h
lib/Transforms/Scalar/JumpThreading.cpp
test/Transforms/JumpThreading/basic.ll
Index: test/Transforms/JumpThreading/basic.ll
===================================================================
--- test/Transforms/JumpThreading/basic.ll
+++ test/Transforms/JumpThreading/basic.ll
@@ -513,4 +513,36 @@
; CHECK: }
}
+; CHECK: define void @h_con(i32 %p) {
+define void @h_con(i32 %p) {
+ %x = icmp ult i32 %p, 5
+ br i1 %x, label %l1, label %l2
+
+l1:
+ call void @j()
+ br label %l3
+
+l2:
+ call void @k()
+ br label %l3
+
+l3:
+; CHECK: call void @g() [[CON:#[0-9]+]]
+; CHECK-NOT: call void @g() [[CON]]
+ call void @g() convergent
+ %y = icmp ult i32 %p, 5
+ br i1 %y, label %l4, label %l5
+
+l4:
+ call void @j()
+ ret void
+
+l5:
+ call void @k()
+ ret void
+; CHECK: }
+}
+
+
; CHECK: attributes [[NOD]] = { noduplicate }
+; CHECK: attributes [[CON]] = { convergent }
Index: lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- lib/Transforms/Scalar/JumpThreading.cpp
+++ lib/Transforms/Scalar/JumpThreading.cpp
@@ -273,7 +273,7 @@
// as having cost of 2 total, and if they are a vector intrinsic, we model
// them as having cost 1.
if (const CallInst *CI = dyn_cast<CallInst>(I)) {
- if (CI->cannotDuplicate())
+ if (CI->cannotDuplicate() || CI->isConvergent())
// Blocks with NoDuplicate are modelled as having infinite cost, so they
// are never duplicated.
return ~0U;
Index: include/llvm/IR/Instructions.h
===================================================================
--- include/llvm/IR/Instructions.h
+++ include/llvm/IR/Instructions.h
@@ -1634,6 +1634,12 @@
addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
}
+ /// \brief Determine if the call is convergent
+ bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
+ void setConvergent() {
+ addAttribute(AttributeSet::FunctionIndex, Attribute::Convergent);
+ }
+
/// \brief Determine if the call returns a structure through first
/// pointer argument.
bool hasStructRetAttr() const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12484.33545.patch
Type: text/x-patch
Size: 2063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150830/332ed3b3/attachment-0001.bin>
More information about the llvm-commits
mailing list