[PATCH] D18155: Instcombine: try to avoid wasted work in ConstantFold

escha via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 15 22:09:14 PDT 2016

escha added a comment.

Ah okay, I think now (looking at this a bit more) I understand why this cost keeps showing up in the profile. Like you said, it also happens during the main InstCombine run as well. Specifically, we have lots of loads and intrinsics with all constant operands that can't be folded (since they're runtime, not compile-time constants). So when running ConstantFoldInstruction, it's forced to call SimplifyConstantExpr on every operand, even though that ends up doing absolutely nothing. The results then get thrown away because you can't constant-fold a load to something whose value isn't known at compile time.

This cost shows up about 3 times in InstCombine:

1. ~4% of time: constantfoldinstruction on init (this patch tries to eliminate that cost)
2. ~4% of time: constantfoldconstantexpr on init (in this patch, but not saved)
3. ~4% of time: constantfoldinstruction during the main loop

My guess is most of these are doing absolutely nothing useful, but I don't know enough about constexprs or the design of instcombine to understand why it's done this way.



More information about the llvm-commits mailing list