Thanks for all the feedback.
I had not realized that InstCombine did those kinds of fold (replacing (freeze undef)
by constants).
That might work for at least some situation.
I imagine that we typically want to replace (freeze undef)
by:
- zero if it for example is used by OR/ADD/MUL
- minus one if it for example is used by AND
- the value C if for example is used by a BUILD_VECTOR, when a majority of the other operands are C
So some basic heuristic based on the using operations. And in some cases we also want to look at other operands for the users.
PS. A context to why I started to think about these things is the regressions seen in the pull-request: [SelectionDAG] Treat CopyFromReg as freezing the value by bjope · Pull Request #85932 · llvm/llvm-project · GitHub . And it seems like X86TargetLowering::LowerBUILD_VECTOR is trying to deal with this in it’s own way when it comes to BUILD_VECTOR:s. If we for example add a more general solution for this in DAGCombiner::visitFreeze, then I guess X86 wouldn’t need their own hack.