I have a fraction of code using BGL that the MS compiler has for some reason optimized into oblivion. While this is not a boost problem per se, since it appears in a compiler I have not had problems with, I suspect all those templates are confusing the MS compiler somehow.
The symptom is that when I get a property of an edge, then test on that property and branch, the test is removed from the compiled assembly.
Here is the code:
//header
typedef property<edge_weight_t, unsigned> EdgeCountProperty;
typedef adjacency_list<vecS, vecS, bidirectionalS, no_property, EdgeCountProperty> Graph;
typedef graph_traits<Graph>::out_edge_iterator OutEdgeIter;
.....
//code
property_map<Graph, edge_weight_t>::type wgt = get(edge_weight, g);
OutEdgeIter ei, ee, eMax;
unsigned nTopWgt = 0;
unsigned nChk = 0;
for(tie(ei, ee) = out_edges(v, g), eMax = ee; ei != ee; ++ei)
{
nChk = wgt[*ei];
////////This 'if' is skipped, the code acts like nChk > nTopWgt is always TRUE, even when it ain't!!
if(nChk > nTopWgt);
{
nTopWgt = nChk;
eMax = ei;
}
}
Here is the assembly:
OutEdgeIter ei, ee, eMax;
00420514 lea ecx,[ei]
00420517 call boost::detail::out_edge_iter<std::vector<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,unsigned int,boost::detail::edge_desc_impl<boost::bidirectional_tag,unsigned int>,int>::out_edge_iter<std::vector<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::e
0042051C lea ecx,[ee]
0042051F call boost::detail::out_edge_iter<std::vector<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,unsigned int,boost::detail::edge_desc_impl<boost::bidirectional_tag,unsigned int>,int>::out_edge_iter<std::vector<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::e
00420524 lea ecx,[eMax]
00420527 call boost::detail::out_edge_iter<std::vector<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,unsigned int,boost::detail::edge_desc_impl<boost::bidirectional_tag,unsigned int>,int>::out_edge_iter<std::vector<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::e
unsigned nTopWgt = 0;
0042052C mov dword ptr [nTopWgt],0
unsigned nChk = 0;
00420533 mov dword ptr [nChk],0
for(tie(ei, ee) = out_edges(v, g), eMax = ee; ei != ee; ++ei)
0042053A mov eax,dword ptr [g]
0042053D push eax
0042053E mov ecx,dword ptr [v]
00420541 mov edx,dword ptr [ecx]
00420543 push edx
00420544 lea eax,[ebp-198h]
0042054A push eax
0042054B call @ILT+5420(??$out_edges@Uconfig@?$adj_list_gen@V?$adjacency_list@UvecS@boost@@U12@UbidirectionalS@2@Uno_property@2@U?$property@W4edge_weight_t@boost@@IUno_property@2
@@2@U42@UlistS@2@@boost@@UvecS@2@U32@UbidirectionalS@2@Uno_property@2@U?$property@W4edge_weight_t@boost@@IUno_property@2@@2@U52@UlistS@2@@detail@boost@@U?$bidirectional_graph_helper_with_property@Uconfig@?$adj_list_gen@V?$adjacency_list@UvecS
@boost@@U12@UbidirectionalS@2@Uno_property@2@U?$property@W4edge_weight_t@boost@@IUno_property@2@@2@U42@UlistS@2@@boost@@UvecS@2@U32@UbidirectionalS@2@Uno_property@2@U?$property@W4edge_weight_t@boost@@IUno_property@2@@2@U52
@UlistS@2@@detail@boost@@@4@@boost@@YA?AU?$pair@U?$out_edge_iter@Viterator@?$vector@V?$sei_@IViterator@?$list@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@V?$allocator@U?$list_edge@IU?$property@W4edge
_weight_t@boost@@IUno_property@2@@boost@@@boost@@@std@@@std@@U?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@detail@boost@@V?$allocator@
00420550 add esp,0Ch
00420553 push eax
00420554 lea ecx,[ee]
00420557 push ecx
00420558 lea edx,[ei]
0042055B push edx
0042055C lea eax,[ebp-1A8h]
00420562 push eax
00420563 call @ILT+4705(??$tie@U?$out_edge_iter@Viterator
@?$vector@V?$sei_@IViterator@?$list@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@V?$allocator@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@@std@@@std@@
U?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@detail@boost@@V?$allocator@V?$sei_@IViterator@?$list@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@V?$allocator@U?$list_edge@IU?$property@W4edge
_weight_t@boost@@IUno_property@2@@boost@@@boost@@@std@@@std@@U?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@detail@boost@@@std@@@std@@IV?$edge_desc_impl@Ubidirectional_tag@boost@@I@detail@boost@@H@detail@boost@@U123@@
tuples@boost@@YA?AV?$tuple@AAU?$out_edge_iter@Viterator@?$vector@V?$sei_@IViterator@?$list@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@V?$allocator@U?$list_edge@IU?$property@W4edge_weight_t@boost@@
IUno_property@2@@boost@@@boost@@@std@@@std@
00420568 add esp,0Ch
0042056B mov ecx,eax
0042056D call @ILT+2355(??$?4U?$out_edge_iter@Viterator@?$vector@V?$sei_@IViterator@?$list@U?$list_edge@IU
?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@V?$allocator@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@@std@@@std@@U?$property@W4edge_weight_t@boost@@IUno_property@2
@@boost@@@detail@boost@@V?$allocator@V?$sei_@IViterator@?$list@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@V?$allocator@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2
@@boost@@@boost@@@std@@@std@@U?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@detail@boost@@@std@@@std@@IV?$edge_desc_impl@Ubidirectional_tag@boost@@I@detail@boost@@H@detail@boost@@U012@@?$tuple@AAU?$out_edge_iter@Viterator
@?$vector@V?$sei_@IViterator@?$list@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@V?$allocator@U?$list_edge@IU?$property@W4edge_weight_t@boost@@IUno_property@2@@boost@@@boost@@@std@@@std@@
U?$property@W4edge_w
00420572 mov ecx,dword ptr [ee]
00420575 mov dword ptr [eMax],ecx
00420578 mov edx,dword ptr [ebp-24h]
0042057B mov dword ptr [ebp-34h],edx
0042057E jmp foo+0B8h (420588h)
00420580 lea ecx,[ei]
00420583 call boost::iterator_facade<boost::detail::out_edge_iter<std::vector<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,unsigned int,boost::detail::edge_desc_impl<boost::bidirectional_tag,unsigned int>,int>,boost::detail::edge_desc_impl<boost::bidirectional_tag,unsigned int>,boost::random_access_traversal_tag,bo
00420588 lea eax,[ee]
0042058B push eax
0042058C lea ecx,[ei]
0042058F push ecx
00420590 call boost::operator!=<boost::detail::out_edge_iter<std::vector<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,unsigned int,boost::detail::edge_desc_impl<boost::bidirectional_tag,unsigned int>,int>,boost::detail::edge_desc_impl<boost::bidirectional_tag,unsigned int>,boost::random_access_traversal_tag,boost::
00420595 add esp,8
00420598 movzx edx,al
0042059B test edx,edx
0042059D je foo+114h (4205E4h)
{
nChk = wgt[*ei];
0042059F lea eax,[ebp-180h]
004205A5 push eax
004205A6 lea ecx,[ei]
004205A9 call boost::iterator_facade<boost::detail::out_edge_iter<std::vector<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::detail::sei_<unsigned int,std::list<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> >,std::allocator<boost::list_edge<unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property> > > >::iterator,unsigned int,boost::detail::edge_desc_impl<boost::bidirectional_tag,unsigned int>,int>,boost::detail::edge_desc_impl<boost::bidirectional_tag,unsigned int>,boost::random_access_traversal_tag,bo
004205AE sub esp,0Ch
004205B1 mov ecx,esp
004205B3 mov edx,dword ptr [eax]
004205B5 mov dword ptr [ecx],edx
004205B7 mov edx,dword ptr [eax+4]
004205BA mov dword ptr [ecx+4],edx
004205BD mov eax,dword ptr [eax+8]
004205C0 mov dword ptr [ecx+8],eax
004205C3 lea ecx,[wgt]
004205C6 call boost::adj_list_edge_property_map<boost::bidirectional_tag,unsigned int,unsigned int &,unsigned int,boost::property<enum boost::edge_weight_t,unsigned int,boost::no_property>,enum boost::edge_weight_t>::operator[] (41E2E3h)
;;LOOK MA! NO 'cmp' INSTRUCTION! WHERE'D IT GO?!!?
004205CB mov ecx,dword ptr [eax]
004205CD mov dword ptr [nChk],ecx
if(nChk > nTopWgt);
{
nTopWgt = nChk;
004205D0 mov eax,dword ptr [nChk]
004205D3 mov dword ptr [nTopWgt],eax
eMax = ei;
004205D6 mov eax,dword ptr [ei]
004205D9 mov dword ptr [eMax],eax
004205DC mov ecx,dword ptr [ebp-14h]
004205DF mov dword ptr [ebp-34h],ecx
}
}
I repeat that this is not a boost issue per se but this bug might show up more often when compiling all those templates ...
Eric