llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.77k stars 10.97k forks source link

[DebugInfo][LoopStrengthReduce] Missing debug location updates for new phi and binop instructions #97510

Open Apochens opened 2 days ago

Apochens commented 2 days ago

LSR-L2406, L2410

[L2406] The new phi instruction NewPH replacing the old phi instruction PH and cast instruction ShadowUse does not inherit any debug location. [L2410] The new binop instruction NewIncr replacing the old binop instruction Incr does not inherit any debug location.

godbolt: https://godbolt.org/z/eGGd9Pxb5 (see %IV.S. and %IV.S.next in the optimized code)

    /* Add new PHINode. */
->  PHINode *NewPH = PHINode::Create(DestTy, 2, "IV.S.", PH->getIterator());

    /* create new increment. '++d' in above example. */
    Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue());
->  BinaryOperator *NewIncr = BinaryOperator::Create(
        Incr->getOpcode() == Instruction::Add ? Instruction::FAdd
                                              : Instruction::FSub,
        NewPH, CFP, "IV.S.next.", Incr->getIterator());

    NewPH->addIncoming(NewInit, PH->getIncomingBlock(Entry));
    NewPH->addIncoming(NewIncr, PH->getIncomingBlock(Latch));

    /* Remove cast operation */
    ShadowUse->replaceAllUsesWith(NewPH);
    ShadowUse->eraseFromParent();
llvmbot commented 2 days ago

@llvm/issue-subscribers-debuginfo

Author: Shan Huang (Apochens)

[**LSR-L2406**](https://github.com/llvm/llvm-project/blob/3641efcf8cb256ddbd20f4add5ce55800cad5399/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp#L2406), [**L2410**](https://github.com/llvm/llvm-project/blob/3641efcf8cb256ddbd20f4add5ce55800cad5399/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp#L2410) [L2406] The new phi instruction `NewPH` replacing the old phi instruction `PH` and cast instruction `ShadowUse` does not inherent any debug location. [L2410] The new binop instruction `NewIncr` replacing the old binop instruction `Incr` does not inherent any debug location. godbolt: https://godbolt.org/z/eGGd9Pxb5 (see `%IV.S.` and `%IV.S.next` in the optimized code) ```cpp /* Add new PHINode. */ -> PHINode *NewPH = PHINode::Create(DestTy, 2, "IV.S.", PH->getIterator()); /* create new increment. '++d' in above example. */ Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue()); -> BinaryOperator *NewIncr = BinaryOperator::Create( Incr->getOpcode() == Instruction::Add ? Instruction::FAdd : Instruction::FSub, NewPH, CFP, "IV.S.next.", Incr->getIterator()); NewPH->addIncoming(NewInit, PH->getIncomingBlock(Entry)); NewPH->addIncoming(NewIncr, PH->getIncomingBlock(Latch)); /* Remove cast operation */ ShadowUse->replaceAllUsesWith(NewPH); ShadowUse->eraseFromParent(); ```