The similarity is that optimization is taking place, and cheating is possible by recognizing a test situation, in order to "game" the test. Compilers can "game" benchmarks by recognizing them specifically and supplying hand-crafted code. The cases which do this have no applicability to non-benchmark code. Just like recognizing that an emissions test is taking place and behaving optimally for that test has no applicability to real driving.