summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Sotkin <alexey.sotkin@intel.com>2016-10-04 18:31:14 +0300
committerYaxun (Sam) Liu <yaxun.liu@amd.com>2016-10-04 11:31:14 -0400
commit8fc9c34d8f6e3dfdb6c566b339479f4c3270c7bf (patch)
tree58c5a97b74d9e2ef108ce061943a530dda2760f8
parent262987e3844f19ffdb6f26f92c9c26212645444f (diff)
Changing placement of lowered constant expressions (#188)
According to SPIRV specification (p2.4): "All OpVariable instructions in a function must be in the first block in the function. These instructions, together with any immediately preceding OpLine instructions, must be the first instructions in that block." Therefore, lowered constant expressions must not be inserted at the beginig of the basic block. Insert it before the current instruction if the current basic block is the first one in the function. Otherwise insert it at the end of the first basic block in the function. This partially fixes #50
-rw-r--r--lib/SPIRV/SPIRVLowerConstExpr.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/SPIRV/SPIRVLowerConstExpr.cpp b/lib/SPIRV/SPIRVLowerConstExpr.cpp
index 82796a0..e27b479 100644
--- a/lib/SPIRV/SPIRVLowerConstExpr.cpp
+++ b/lib/SPIRV/SPIRVLowerConstExpr.cpp
@@ -132,18 +132,19 @@ SPIRVLowerConstExpr::visit(Module *M) {
if (auto CE = dyn_cast<ConstantExpr>(Op)) {
SPIRVDBG(dbgs() << "[lowerConstantExpressions] " << *CE;)
auto ReplInst = CE->getAsInstruction();
- ReplInst->insertBefore(FBegin->begin());
+ auto InsPoint = II->getParent() == FBegin ? II : &FBegin->back();
+ ReplInst->insertBefore(InsPoint);
SPIRVDBG(dbgs() << " -> " << *ReplInst << '\n';)
WorkList.push_front(ReplInst);
std::vector<Instruction *> Users;
- // Do not replace use during iteration of use. Do it in another loop.
- for (auto U:CE->users()){
+ // Do not replace use during iteration of use. Do it in another loop
+ for (auto U:CE->users()) {
SPIRVDBG(dbgs() << "[lowerConstantExpressions] Use: " <<
*U << '\n';)
if (auto InstUser = dyn_cast<Instruction>(U)) {
- if (InstUser->getParent()->getParent() != I)
- continue;
- Users.push_back(InstUser);
+ // Only replace users in scope of current function
+ if (InstUser->getParent()->getParent() == I)
+ Users.push_back(InstUser);
}
}
for (auto &User:Users)