This is an archive of the discontinued LLVM Phabricator instance.

X86: Don't fold TEST into ADD ...@GOTTPOFF/GOTNTPOFF/INDNTPOFF
ClosedPublic

Authored by jyknight on Aug 11 2022, 1:36 PM.

Details

Summary

The linker may convert such an ADD into a LEA, so we must not
use the EFLAGS output.

This causes miscompiles with ubsan after bacdf80f42b46044262e97e98398d1bd0b75900d
added llvm.threadlocal.address -- previously, global variables were
known to be non-null, but the intrinsic is not currently known to return
nonnull. (That should be corrected, but it shouldn't've caused
miscompiles!)

Diff Detail

Event Timeline

jyknight created this revision.Aug 11 2022, 1:36 PM
jyknight requested review of this revision.Aug 11 2022, 1:36 PM
Herald added a project: Restricted Project. · View Herald Transcript
craig.topper added inline comments.Aug 11 2022, 1:51 PM
llvm/lib/Target/SPIRV/SPIRVDuplicatesTracker.cpp
82 ↗(On Diff #451967)

Unrelated change?

llvm/lib/Target/X86/X86InstrInfo.cpp
4091

80 columns

MaskRay added inline comments.Aug 11 2022, 1:57 PM
llvm/lib/Target/X86/X86InstrInfo.cpp
4091

Can use llvm::is_contained({...}, Flags) to make this shorter.

MaskRay accepted this revision.Aug 11 2022, 2:04 PM

This causes miscompiles with ubsan after bacdf80f42b46044262e97e98398d1bd0b75900d

ubsan can be more specific, -fsanitize=null

llvm/lib/Target/X86/X86InstrInfo.cpp
4085

x86-64 psABI should be more authoritative than ""ELF Handling for Thread-Local Storage"".

This revision is now accepted and ready to land.Aug 11 2022, 2:04 PM
zuban32 requested changes to this revision.Aug 11 2022, 4:28 PM
zuban32 added inline comments.
llvm/lib/Target/SPIRV/SPIRVDuplicatesTracker.cpp
82 ↗(On Diff #451967)

Agreed, pls remove

This revision now requires changes to proceed.Aug 11 2022, 4:28 PM
jyknight updated this revision to Diff 452176.Aug 12 2022, 7:02 AM
jyknight marked 5 inline comments as done.

Address minor issues.

llvm/lib/Target/X86/X86InstrInfo.cpp
4085

OTHER references in the code point to this document. E.g. X86TargetLowering::shouldReduceLoadWidth in llvm/lib/Target/X86/X86ISelLowering.cpp:

// "ELF Handling for Thread-Local Storage" specifies that R_X86_64_GOTTPOFF
// relocation target a movq or addq instruction: don't let the load shrink.

and the definition of MO_GOTTPOFF in llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h:

/// See 'ELF Handling for Thread-Local Storage' for more details.
///    SYMBOL_LABEL @GOTTPOFF
MO_GOTTPOFF,

I'd prefer to be consistent, so will leave this.

4091

Turns out this is a little annoying, given that the first arg turns out to be initializer_list<X86II::TOF>, but getTargetFlags returns unsigned int, and llvm::is_contained is template <typename T> constexpr bool is_contained(std::initializer_list<T> Set, T Value).

I could workaround with explicit casts here, but that feels uglier than just using || so I'll just leave this alone. (I expect that is_contained should be fixed, but I'm not doing that in this change).

zuban32 accepted this revision.Aug 12 2022, 10:16 AM

LGTM regarding removal of unrelated SPIR-V code

This revision is now accepted and ready to land.Aug 12 2022, 10:16 AM