This is an archive of the discontinued LLVM Phabricator instance.

[X86] Check the address in machine verifier
ClosedPublic

Authored by skan on Apr 26 2022, 7:34 AM.

Details

Summary
  1. The scale factor must be 1, 2, 4, 8
  2. The displacement must fit in 32-bit signed integer

Noticed by: https://github.com/llvm/llvm-project/issues/55091

Diff Detail

Event Timeline

skan created this revision.Apr 26 2022, 7:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2022, 7:35 AM
skan requested review of this revision.Apr 26 2022, 7:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2022, 7:35 AM
fhahn added inline comments.Apr 26 2022, 7:41 AM
llvm/test/CodeGen/MIR/X86/machine-verifier-address.mir
9

Is the IR here needed? From a quick glance, the only references in the MIR are the basic block names bb and bb2, but those can be removed I think.

skan updated this revision to Diff 425217.Apr 26 2022, 7:55 AM
skan marked an inline comment as done.

Remove redundant IR/MIR in the test

skan updated this revision to Diff 425220.Apr 26 2022, 8:02 AM

Updated the test file

  1. Removed dependency on opaque pointer
  2. Checked there are exactly 2 errors
skan updated this revision to Diff 425246.Apr 26 2022, 9:26 AM

Check the scale only when index register is not none

This change fixed three tests:

LLVM :: CodeGen/X86/optimize-compare.mir
LLVM :: CodeGen/X86/segmented-stacks-dynamic.ll
LLVM :: CodeGen/X86/segmented-stacks.ll
skan added inline comments.Apr 26 2022, 9:28 AM
llvm/test/CodeGen/MIR/X86/machine-verifier-address.mir
9

You're right! Done

pengfei accepted this revision.Apr 26 2022, 6:39 PM

LGTM. Thanks!

This revision is now accepted and ready to land.Apr 26 2022, 6:39 PM
pengfei added inline comments.Apr 26 2022, 6:42 PM
llvm/test/CodeGen/MIR/X86/machine-verifier-address.mir
2

I'm curious why we can verify it without option -verify-machineinstrs?

skan added inline comments.Apr 26 2022, 6:49 PM
llvm/test/CodeGen/MIR/X86/machine-verifier-address.mir
2

Because when you feed a MIR to llc w/ option run-pass, the verification for MIR is forced to run.

skan marked an inline comment as done.Apr 26 2022, 6:52 PM
skan added inline comments.
llvm/test/CodeGen/MIR/X86/machine-verifier-address.mir
2

Do we have test coverage that the expensive checks bot runs that would have caught the gather+opaque ptr issue that motivated this patch?

I'm not opposed to this patch, just wondering if it is enough to help us find issues.

skan added a comment.EditedApr 26 2022, 7:30 PM

Do we have test coverage that the expensive checks bot runs that would have caught the gather+opaque ptr issue that motivated this patch?

I'm not opposed to this patch, just wondering if it is enough to help us find issues.

I think so. https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/TargetPassConfig.cpp#L809
Machine verify is enabled when the macro EXPENSIVE_CHECKS is on, so we can expose the "gather+opaque ptr" issue at ISEL stage w/ this patch.

skan added a comment.Apr 26 2022, 7:44 PM

Do we have test coverage that the expensive checks bot runs that would have caught the gather+opaque ptr issue that motivated this patch?

I'm not opposed to this patch, just wondering if it is enough to help us find issues.

I think so. https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/TargetPassConfig.cpp#L809
Machine verify is enabled when the macro EXPENSIVE_CHECKS is on, so we can expose the "gather+opaque ptr" issue at ISEL stage w/ this patch.

If the bot has an expensive check for opaque ptr, then we will have the test converage. ( I'm not sure whether bot has such config)

Do we have test coverage that the expensive checks bot runs that would have caught the gather+opaque ptr issue that motivated this patch?

I'm not opposed to this patch, just wondering if it is enough to help us find issues.

The reported issues didn't mention their origin, but I guess they are not from build bot since Nikita's patch merged for almost 20 days.

llvm/test/CodeGen/MIR/X86/machine-verifier-address.mir
2

Good to know, thanks!

This revision was landed with ongoing or failed builds.Apr 27 2022, 7:05 PM
This revision was automatically updated to reflect the committed changes.