[PATCH] D90391: [gvn] PRE needs to skip convergent intrinsics/calls.
Michael Liao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 29 06:26:46 PDT 2020
hliao created this revision.
hliao added reviewers: fhahn, nikic, mkazantsev, jdoerfert, efriedma.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
hliao requested review of this revision.
- As convergent intrinsics/calls could only be moved to control-equivalent blocks, or more precisely the same divergent branch, PRE needs to skip them.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D90391
Files:
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/pre-skip-convergent.ll
Index: llvm/test/Transforms/GVN/pre-skip-convergent.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GVN/pre-skip-convergent.ll
@@ -0,0 +1,25 @@
+; RUN: opt -S -gvn -o - %s | FileCheck %s
+
+; CHECK-LABEL: @foo
+; CHECK: pre:
+; CHECK-NOT: call i32 @llvm.convergent
+; CHECK: merge:
+define i32 @foo(i1 %cond, i32* %q, i32* %p) {
+entry:
+ %v0 = call i32 @llvm.convergent(i32 0)
+ store i32 %v0, i32* %q
+ br i1 %cond, label %pre, label %merge
+
+pre:
+ %t0 = load i32, i32* %p
+ br label %merge
+
+merge:
+ %m0 = phi i32 [ %t0, %pre ], [ 0, %entry ]
+ %r0 = call i32 @llvm.convergent(i32 %m0)
+ ret i32 %r0
+}
+
+declare i32 @llvm.convergent(i32) #0
+
+attributes #0 = { convergent nounwind readnone }
Index: llvm/lib/Transforms/Scalar/GVN.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVN.cpp
+++ llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2461,9 +2461,13 @@
return false;
// We don't currently value number ANY inline asm calls.
- if (auto *CallB = dyn_cast<CallBase>(CurInst))
+ if (auto *CallB = dyn_cast<CallBase>(CurInst)) {
if (CallB->isInlineAsm())
return false;
+ // Don't do PRE on convergent calls.
+ if (CallB->isConvergent())
+ return false;
+ }
uint32_t ValNo = VN.lookup(CurInst);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90391.301597.patch
Type: text/x-patch
Size: 1362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201029/d015f5b1/attachment.bin>
More information about the llvm-commits
mailing list