https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120894
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Component|middle-end |ipa Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed| |2025-06-30 Severity|normal |enhancement --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This seems related to how std::function optimizing. Basically we don't devirutalize things until late . Before inlining we have: ``` _1 = std::pmr::get_default_resource (); res ={v} {CLOBBER(bob)}; res.D.43232._vptr.memory_resource = &MEM <int (*) ()[7]> [(void *)&_ZTVN12_GLOBAL__N_114StaticResourceE + 16B]; res.buffer = &buf[0]; res.buffer_left = 16; res.upstream = _1; MEM[(struct polymorphic_allocator *)&D.44315] ={v} {CLOBBER(bob)}; MEM[(struct polymorphic_allocator *)&D.44315]._M_resource = &res.D.43232; std::vector<std::byte, std::pmr::polymorphic_allocator<std::byte> >::vector (&vec, 16, &D.44315); ``` And that function was: ``` MEM[(struct _Vector_impl *)this_2(D)].D.43600 = MEM[(const struct polymorphic_allocator &)__a_5(D)]; MEM[(struct _Vector_impl_data *)this_2(D) + 8B] ={v} {CLOBBER(bob)}; MEM[(struct _Vector_impl_data *)this_2(D) + 8B]._M_start = 0B; MEM[(struct _Vector_impl_data *)this_2(D) + 8B]._M_finish = 0B; MEM[(struct _Vector_impl_data *)this_2(D) + 8B]._M_end_of_storage = 0B; if (__n_4(D) != 0) goto <bb 5>; [71.00%] else goto <bb 6>; [29.00%] <bb 5> [local count: 83859236]: _10 = MEM[(struct polymorphic_allocator *)this_2(D)]._M_resource; _11 = *_10._vptr.memory_resource; _12 = MEM[(int (*) () *)_11 + 16B]; _13 = OBJ_TYPE_REF(_12;(struct memory_resource)_10->2B) (_10, __n_4(D), 1); ``` MEM[(struct polymorphic_allocator *)this_2(D)]._M_resource could be optimize to just : MEM[(const struct polymorphic_allocator &)__a_5(D)]._M_resource I think. That might improve things slightly but not enough though.