Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

TargetLowering::computeKnownBitsForTargetNode - constant pool extraction #44285

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR45315
Status NEW
Importance P enhancement
Reported by Simon Pilgrim (llvm-dev@redking.me.uk)
Reported on 2020-03-26 06:32:32 -0700
Last modified on 2020-03-26 12:44:01 -0700
Version trunk
Hardware PC Windows NT
CC craig.topper@gmail.com, efriedma@quicinc.com, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

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?

Quuxplusone commented 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.

Quuxplusone commented 4 years ago
(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.