[PATCH] D62531: SpeculateAroundPHIs: Respect convergent
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 08:55:52 PDT 2019
arsenm created this revision.
arsenm added a reviewer: chandlerc.
Herald added subscribers: nhaehnle, wdng, jvesely.
This would break for speculatable and convergent intrinsic calls.
https://reviews.llvm.org/D62531
Files:
lib/Transforms/Scalar/SpeculateAroundPHIs.cpp
test/Transforms/SpeculateAroundPHIs/AMDGPU/convergent.ll
test/Transforms/SpeculateAroundPHIs/AMDGPU/lit.local.cfg
Index: test/Transforms/SpeculateAroundPHIs/AMDGPU/lit.local.cfg
===================================================================
--- /dev/null
+++ test/Transforms/SpeculateAroundPHIs/AMDGPU/lit.local.cfg
@@ -0,0 +1,3 @@
+if not 'AMDGPU' in config.root.targets:
+ config.unsupported = True
+
Index: test/Transforms/SpeculateAroundPHIs/AMDGPU/convergent.ll
===================================================================
--- /dev/null
+++ test/Transforms/SpeculateAroundPHIs/AMDGPU/convergent.ll
@@ -0,0 +1,35 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes=spec-phis < %s | FileCheck %s
+; Make sure convergent and noduplicate calls aren't duplicated.
+
+declare i32 @llvm.amdgcn.wwm.i32(i32) #0
+
+define i32 @test_convergent(i1 %flag, i32 %arg) #0 {
+; CHECK-LABEL: @test_convergent(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[A:%.*]], label [[B:%.*]]
+; CHECK: a:
+; CHECK-NEXT: br label [[EXIT:%.*]]
+; CHECK: b:
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: [[P:%.*]] = phi i32 [ 7, [[A]] ], [ 11, [[B]] ]
+; CHECK-NEXT: [[SUM:%.*]] = call i32 @llvm.amdgcn.wwm.i32(i32 [[P]])
+; CHECK-NEXT: ret i32 [[SUM]]
+;
+entry:
+ br i1 %flag, label %a, label %b
+
+a:
+ br label %exit
+
+b:
+ br label %exit
+
+exit:
+ %p = phi i32 [ 7, %a ], [ 11, %b ]
+ %sum = call i32 @llvm.amdgcn.wwm.i32(i32 %p)
+ ret i32 %sum
+}
+
+attributes #0 = { nounwind readnone convergent speculatable }
Index: lib/Transforms/Scalar/SpeculateAroundPHIs.cpp
===================================================================
--- lib/Transforms/Scalar/SpeculateAroundPHIs.cpp
+++ lib/Transforms/Scalar/SpeculateAroundPHIs.cpp
@@ -67,6 +67,14 @@
return false;
}
+ if (auto CS = ImmutableCallSite(UI)) {
+ if (CS.isConvergent() || CS.cannotDuplicate()) {
+ LLVM_DEBUG(dbgs() << " Unsafe: convergent "
+ "callsite cannot de duplicated: " << *UI << '\n');
+ return false;
+ }
+ }
+
// FIXME: This check is much too conservative. We're not going to move these
// instructions onto new dynamic paths through the program unless there is
// a call instruction between the use and the PHI node. And memory isn't
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62531.201685.patch
Type: text/x-patch
Size: 2300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190528/43a431c3/attachment.bin>
More information about the llvm-commits
mailing list