Open Quuxplusone opened 3 years ago
Attached jmpq_fold.ll
(2160 bytes, text/plain): reproducer
dipatch1 and dispatch15 have a different DAG shape after
X86DAGToDAGISel::PreprocessISelDAG (see attachments). There's an optimisation
to "try moving call address load from outside callseq_start to just before the
call to allow it to be folded." It doesn't handle a multi-parameter case for
tail calls.
The following patch fixes it for me:
@@ -778,11 +778,20 @@ static bool isCalleeLoad(SDValue Callee, SDValue &Chain,
bool HasCallSeq) {
LD->getExtensionType() != ISD::NON_EXTLOAD)
return false;
- // Now let's find the callseq_start.
- while (HasCallSeq && Chain.getOpcode() != ISD::CALLSEQ_START) {
- if (!Chain.hasOneUse())
- return false;
- Chain = Chain.getOperand(0);
+ if (HasCallSeq) {
+ // Now let's find the callseq_start.
+ while (Chain.getOpcode() != ISD::CALLSEQ_START) {
+ if (!Chain.hasOneUse())
+ return false;
+ Chain = Chain.getOperand(0);
+ }
+ } else if (Chain.getOpcode() == ISD::CopyToReg) {
+ // Locate first CopyToReg in the sequence of CopyToReg-s.
+ while (Chain.getOperand(0).getOpcode() == ISD::CopyToReg) {
+ if (!Chain.hasOneUse())
+ return false;
+ Chain = Chain.getOperand(0);
+ }
}
Attached dispatch1.png
(168300 bytes, image/png): dispatch1 DAG after X86DAGToDAGISel::PreprocessISelDAG
Attached dispatch15.png
(135385 bytes, image/png): dispatch15 DAG after X86DAGToDAGISel::PreprocessISelDAG
jmpq_fold.ll
(2160 bytes, text/plain)dispatch1.png
(168300 bytes, image/png)dispatch15.png
(135385 bytes, image/png)