This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Handle IntToPtr constants in dbg.value
ClosedPublic

Authored by fdeazeve on Jul 27 2022, 9:11 AM.

Details

Summary

Currently, the IR to MIR translator can only handle two kinds of constant
inputs to dbg.values intrinsics: constant integers and constant floats. In
particular, it cannot handle pointers created from IntToPtr ConstantExpression
objects.

This patch addresses the limitation above by replacing the IntToPtr with
its input integer prior to converting the dbg.value input.

Diff Detail

Event Timeline

fdeazeve created this revision.Jul 27 2022, 9:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2022, 9:11 AM
fdeazeve requested review of this revision.Jul 27 2022, 9:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2022, 9:11 AM
fdeazeve updated this revision to Diff 448069.Jul 27 2022, 9:13 AM
fdeazeve edited the summary of this revision. (Show Details)

Fixed typo in commit message

aprantl accepted this revision.Jul 27 2022, 9:51 AM

Thanks! LGTM with the one inline comment addressed.

llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
112
  1. I don't think this code path is tested?
  2. Is this inttoptr(float) actually legal LLVM IR?
This revision is now accepted and ready to land.Jul 27 2022, 9:51 AM
fdeazeve added inline comments.Jul 27 2022, 9:58 AM
llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
112

Is this inttoptr(float) actually legal LLVM IR?

No, this kind of IR would fail the verifier

I don't think this code path is tested?

I see the source of confusion now. I only changed this line to keep the spirit of the "type switch" that is going on here, i.e. the same value is tested on every branch.
For example, if the lambda ever changed to strip other things (for example some new float to ptr cast instruction), then the rest of the code wouldn't need to change.

Thoughts? I can argue both ways

aprantl added inline comments.Jul 27 2022, 10:00 AM
llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
112

Ah okay, that makes sense!

All tests failures are due to this linke error: "/usr/bin/ld: cannot find -lomptarget.devicertl: No such file or directory'
Probably some unrelated issue with lib OpenMP

All tests failures are due to this linke error: "/usr/bin/ld: cannot find -lomptarget.devicertl: No such file or directory'
Probably some unrelated issue with lib OpenMP

Yeah there's no way that is related to this patch.

This revision was landed with ongoing or failed builds.Jul 27 2022, 1:42 PM
This revision was automatically updated to reflect the committed changes.
nikic added a subscriber: nikic.Jul 27 2022, 1:56 PM
nikic added inline comments.
llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
103

What's the cast<const Constant>() for?

fdeazeve added inline comments.Jul 27 2022, 2:05 PM
llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
103

This was done to drive the lambda return type deduction to const Constant*, which is the type of &C.

I thought getOperand would return a Value, but now that you mentioned it, I see that I was wrong, it already returns a Constant.

So I think this code could have been rewritten with an explicit return type of the lambda and the cast removed?

cpp
auto *NumericConstant = [&] () -> const Constant* {
    if (const auto *CE = dyn_cast<ConstantExpr>(&C))
      if (CE->getOpcode() == Instruction::IntToPtr)
        return CE->getOperand(0);
    return &C;
  }();