This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Fix known bits for G_ASSERT_ALIGN.
ClosedPublic

Authored by aemerson on Sep 21 2022, 12:42 PM.

Details

Summary

I don't know what was going on originally with these tests. It seems reasonable to have the immediate be the same byte alignment unit as the IR, in which case we need to take the log2 in order to set the right number of low bits.

This fixes a miscompile in chromium.

Diff Detail

Event Timeline

aemerson created this revision.Sep 21 2022, 12:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2022, 12:42 PM
aemerson requested review of this revision.Sep 21 2022, 12:42 PM
This revision is now accepted and ready to land.Sep 21 2022, 1:23 PM
This revision was landed with ongoing or failed builds.Sep 21 2022, 1:46 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Sep 21 2022, 1:53 PM

This breaks building on platforms where int64_t is long: http://45.33.8.238/linux/87097/step_4.txt

arsenm added inline comments.Sep 21 2022, 1:58 PM
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
42

This might have been a misuse

475

I thought 0 would be rejected by the verifier. This shouldn’t have been produced

I am getting this error with the latest main:

/home/dobercea/upstream/llvm-project/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp: In member function ‘llvm::Align llvm::GISelKnownBits::computeKnownAlignment(llvm::Register, unsigned int)’:
/home/dobercea/upstream/llvm-project/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp:42:58: error: no matching function for call to ‘max(long long int, int64_t)’
   42 |     return Align(std::max(1LL, MI->getOperand(2).getImm()));
        |                                                        ^

I am getting this error with the latest main:

/home/dobercea/upstream/llvm-project/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp: In member function ‘llvm::Align llvm::GISelKnownBits::computeKnownAlignment(llvm::Register, unsigned int)’:
/home/dobercea/upstream/llvm-project/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp:42:58: error: no matching function for call to ‘max(long long int, int64_t)’
   42 |     return Align(std::max(1LL, MI->getOperand(2).getImm()));
        |                                                        ^

Sorry about that, someone fixed this in 2d975f1efe6cdb4f6303cfe33a3a06cbe02e755a

aemerson added inline comments.Sep 22 2022, 2:27 AM
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
475

Ok I'll look into adding a verifier check and removing this handling for 0.

arsenm added inline comments.Sep 22 2022, 10:19 AM
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
475

Actually this is a different change than I thought. The immediate was supposed to be directly interpreted as the log2 value. Somewhere must be producing it with the raw alignment instead of the correct log2 value

475

0 should still be invalid though

aemerson added inline comments.Sep 22 2022, 11:30 AM
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
475

Why bother with encoding it as a bit mask when other places use the number of bytes?

arsenm added inline comments.Sep 22 2022, 11:30 AM
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
475

It's not a bitmask it's a number of bits. The only use is here to set a number of bits

aemerson added inline comments.Sep 22 2022, 12:10 PM
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
475

Right ok but same point, why deviate from the semantics of "alignment" at other IR levels?

arsenm added inline comments.Sep 28 2022, 10:15 AM
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
475

I guess it doesn't really matter but everywhere needs to be consistent. I thought a value you can directly use would be more convenient