>And also, I don't need to detect if-then-else loop, because this will>execute only once. What I need to detect is "while loop", "for loop">etc. As I said earlier, I can ignore exception, as it would happen>less frequently.

Perhaps you should clarify some terms:

What do you mean by "detect loops using H/W"? Hardware?

Why do you consider if-then-else as loops?

Do you want to do a static or a dynamic analysis?

One of the principles of control flow analysis is the abstraction from
physical addresses, so that the arrangement of sequential code in
memory becomes unimportant. That abstraction is important for any
compiled code, since modern compilers may arrange the code in a
most-probable-next-target order, regardless of the static structure of
the source code. A loop then exists when a jump goes to a node which
has already been visited before, during the analysis of the control
flow graph. Dead code, and consequently jumps never taken, is
eliminated by control flow analysis. More code can be eliminated when
conditions can be detected as being always true/false.

In a dynamic analysis (cache implementation...) a peephole optimizer
with an LRU algorithm can be used, so that the Least Recently Used
parts of the code will remain in the cache, regardless of any jump
directions.