summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2019-06-17 17:52:35 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2019-06-17 17:52:35 +0000
commit6d741f29ec8f41d949fb08578488abdfd1685f9b (patch)
tree9d2c1ad5290929938b6b001160dbbf417b92ee9c /llvm/lib
parentad04e7ad42663161ebc164cb0098826b38a4e0d2 (diff)
downloadbcm5719-llvm-6d741f29ec8f41d949fb08578488abdfd1685f9b.tar.gz
bcm5719-llvm-6d741f29ec8f41d949fb08578488abdfd1685f9b.zip
AMDGPU: Fold readlane/readfirstlane calls
llvm-svn: 363587
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 347aeb6989a..e366c379e9b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3781,6 +3781,30 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// A constant value is trivially uniform.
if (Constant *C = dyn_cast<Constant>(II->getArgOperand(0)))
return replaceInstUsesWith(*II, C);
+
+ // The rest of these may not be safe if the exec may not be the same between
+ // the def and use.
+ Value *Src = II->getArgOperand(0);
+ Instruction *SrcInst = dyn_cast<Instruction>(Src);
+ if (SrcInst && SrcInst->getParent() != II->getParent())
+ break;
+
+ // readfirstlane (readfirstlane x) -> readfirstlane x
+ // readlane (readfirstlane x), y -> readfirstlane x
+ if (match(Src, m_Intrinsic<Intrinsic::amdgcn_readfirstlane>()))
+ return replaceInstUsesWith(*II, Src);
+
+ if (IID == Intrinsic::amdgcn_readfirstlane) {
+ // readfirstlane (readlane x, y) -> readlane x, y
+ if (match(Src, m_Intrinsic<Intrinsic::amdgcn_readlane>()))
+ return replaceInstUsesWith(*II, Src);
+ } else {
+ // readlane (readlane x, y), y -> readlane x, y
+ if (match(Src, m_Intrinsic<Intrinsic::amdgcn_readlane>(
+ m_Value(), m_Specific(II->getArgOperand(1)))))
+ return replaceInstUsesWith(*II, Src);
+ }
+
break;
}
case Intrinsic::stackrestore: {
OpenPOWER on IntegriCloud