Open Quuxplusone opened 4 years ago
Isn't this a general problem with all constant pools? I'm not sure how limiting it to target-specific nodes helps, unless there's some rule I'm not aware of.
Can we somehow detect this class of infinite loop automatically, without caring about the specific nodes involved? For example, the compiler computes the known bits for VBROADCAST_LOAD, tries to replace it with a constant, ends up recreating the VBROADCAST_LOAD, then gives up because we'd be replacing the node with itself.
(In reply to Eli Friedman from comment #1)
> Isn't this a general problem with all constant pools? I'm not sure how
> limiting it to target-specific nodes helps, unless there's some rule I'm not
> aware of.
Yes and we already prevent constant folding for ISD::BUILD_VECTOR and ISD::LOAD
inside SimplifyDemandedBits, its the target specific ones that are tricker.
We can't safely extract the knownbits of target constant pools (e.g. X86ISD::VBROADCAST_LOAD) because SimplifyDemandedBits may then attempt to constant fold it, which then infinite loops as it gets relowered to X86ISD::VBROADCAST_LOAD again......
As an initial stopgap, we could just not constant fold if SimplifyDemandedBits encounters an opcode above FIRST_TARGET_MEMORY_OPCODE (or is a MemSDNode?) but this doesn't address non-loading target patterns that might be used for constant creation, so maybe we need some way to flag that a computeKnownBitsForTargetNode call came from a lowered constant?