I am pretty sure your theory is false.
-Cllvm-args=-print-after-all shows that the final IR before instruction selection has no calls (though it has a bunch of loads, stores, and compares that should have been constant folded) and the MachineIR is just "ret 1" aside from debuginfo
Oh no, the MIR also has stack slots allocated, even though they are dead. That might have something to do with it?
# *** IR Dump After Finalize ISel and expand pseudo-instructions ***: # Machine code for function _RNvCsbDqzXfLQacH_7example7compare: IsSSA, TracksLiveness Frame Objects: fi#0: size=4, align=1, at location [SP+8] fi#1: size=4, align=4, at location [SP+8] bb.0 (%ir-block.0): LIFETIME_START %stack.1 LIFETIME_START %stack.0 LIFETIME_END %stack.1 LIFETIME_END %stack.0 %0:gr8 = MOV8ri 1 $al = COPY %0:gr8 RET 0, $al
(this is with
LLVM expands memcmp/bcmp in the ExpandMemcmp pass prior to SDAG lowering. As this happens very late, there's no opportunity for general combining passes (like InstCombine) to run anymore. The simplification happens in DAGCombine, which is not able to eliminate those ligetime.start/end pairs.
I think there were some plans to move this expansion into the opt pipeline...
Indeed: https://reviews.llvm.org/D60318 Looks like it got applied + reverted two times.