@@ -62,7 +62,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableType(Variable *var, LLVMInstructi
6262 } else if (isElse (ins)) {
6363 // Skip if branch if coming from else
6464 firstElseBranch = ins;
65- ins = skipBranch (ins);
65+ ins = branchStart (ins);
6666 continue ;
6767 } else if (isVariableWrite (ins, var) && !isWriteNoOp (ins)) {
6868 if (level <= 0 ) { // ignore nested branches (they're handled by the branch analyzer)
@@ -134,7 +134,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd(Variable *
134134 } else
135135 return Compiler::StaticType::Unknown;
136136
137- ins = skipBranch (ins);
137+ ins = branchStart (ins);
138138
139139 if (isElse (ins)) {
140140 // Process if branch (the else branch is already processed)
@@ -150,7 +150,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd(Variable *
150150 } else
151151 return Compiler::StaticType::Unknown;
152152
153- ins = skipBranch (ins);
153+ ins = branchStart (ins);
154154 }
155155 } else if (isVariableWrite (ins, var) && !isWriteNoOp (ins)) {
156156 // Variable write instruction
@@ -194,29 +194,33 @@ LLVMInstruction *LLVMTypeAnalyzer::branchEnd(LLVMInstruction *start) const
194194 return ins;
195195}
196196
197- LLVMInstruction *LLVMTypeAnalyzer::skipBranch (LLVMInstruction *pos ) const
197+ LLVMInstruction *LLVMTypeAnalyzer::branchStart (LLVMInstruction *end ) const
198198{
199+ assert (end);
200+ assert (isLoopEnd (end) || isIfEnd (end) || isElse (end));
201+
202+ // Find loop/if statement/else branch start
203+ LLVMInstruction *ins = end->previous ;
199204 int level = 0 ;
200- pos = pos->previous ;
201205
202- while (pos && !((isLoopStart (pos ) || isIfStart (pos )) && level == 0 )) {
203- if (isLoopStart (pos ) || isIfStart (pos )) {
206+ while (ins && !((isLoopStart (ins ) || isIfStart (ins )) && level == 0 )) {
207+ if (isLoopStart (ins ) || isIfStart (ins )) {
204208 assert (level > 0 );
205209 level--;
206210 }
207211
208- if (isLoopEnd (pos ) || isIfEnd (pos ) || isElse (pos )) {
209- if (isElse (pos ) && level == 0 )
212+ if (isLoopEnd (ins ) || isIfEnd (ins ) || isElse (ins )) {
213+ if (isElse (ins ) && level == 0 )
210214 break ;
211215
212216 level++;
213217 }
214218
215- pos = pos ->previous ;
219+ ins = ins ->previous ;
216220 };
217221
218- assert (pos );
219- return pos ;
222+ assert (ins );
223+ return ins ;
220224}
221225
222226bool LLVMTypeAnalyzer::isLoopStart (LLVMInstruction *ins) const
0 commit comments