This is an archive of the discontinued LLVM Phabricator instance.

[TTI][NFCI] Introduce two new target transform hooks
Needs ReviewPublic

Authored by jdoerfert on Jul 20 2023, 3:42 PM.

Details

Summary

TargetTransformInfo::willResultInPoisonOnCallEdge and
TargetTransformInfo::isValidCallBaseForCallee allow the middle end to
prune potential call targets if such a call would be undefined.
The default implementation does not try to be very agressive, TODO's are
placed for improvments, or target specific hooks.

Diff Detail

Event Timeline

jdoerfert created this revision.Jul 20 2023, 3:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2023, 3:42 PM
jdoerfert requested review of this revision.Jul 20 2023, 3:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2023, 3:42 PM
arsenm added inline comments.Jul 20 2023, 3:46 PM
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
822–833

Move this into Attributes somewhere to check for ABI compatible attributes?

823

Should also check inreg matches

823

Also careful of arbitrary string attributes?

arsenm added inline comments.Jul 20 2023, 3:47 PM
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
843

signext and zeroext probably need to match, at least for the return

jdoerfert updated this revision to Diff 542711.Jul 20 2023, 3:50 PM

Check for sized and scalable

arsenm added inline comments.Jul 20 2023, 3:50 PM
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
823

Maybe skip address space pairs that aren't isNoopAddrSpaceCast

jdoerfert updated this revision to Diff 542722.Jul 20 2023, 4:57 PM

Address comments.

nikic requested changes to this revision.Jul 21 2023, 12:34 AM
nikic added a subscriber: aeubanks.

Can you please explain what the motivation for this is? I mean, I can see the benefit in theory, but I'm not clear on where this would help in practice.

This seems like a very dangerous change to me. If we want to do this, I'd recommend to go for a default implementation of "always valid" and then carve out very specific exceptions based on real-world motivation.

Two immediate issues I see here are:

  • On x86_32 at least, clang will pass arguments by value, even though they really have indirect byval ABI. The reasoning is that LLVM will actually lowering those arguments with the correct ABI, and passing values as SSA values is of course much more amenable to optimization. However, Rust will instead generate the "correct" byval ABI. These calls are incompatible at the IR level (you will have a byval ptr argument on one side an something like i32 on the other -- or worse, a non-byval ptr that has a completely different meaning!) but become compatible after lowering. Clang is doing something extremely fishy here, but we still need to make sure that this does not get miscompiled (as your current code will do, on multiple levels).
  • There are recurring problems with callee vs caller ABI attribute mismatches. IIRC there were some attempts to clean this up as part of the opaque pointer migration, by making lowering only consider callee ABI attributes. However, this ran into a whole series of issues with attribute mismatches in practice, and ended up getting reverted. Maybe @aeubanks has more context on that. Missing signext/zeroext attributes are also a recurring problem for targets like s390x. And this also plays into the previous point: A ptr with and without byval are not necessarily an ABI mismatch after lowering.
This revision now requires changes to proceed.Jul 21 2023, 12:34 AM
arsenm added inline comments.Jul 21 2023, 4:43 AM
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
846

I think you missed the base call site CC matches function CC

jdoerfert updated this revision to Diff 543098.Jul 21 2023, 3:33 PM
jdoerfert edited the summary of this revision. (Show Details)

Make it less aggressive. Mostly based on noundef and no more attribute mismatch identification.

arsenm added inline comments.Aug 14 2023, 2:55 PM
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
855

I didn't know any mismatches were allowed?

856

Should just fix these underlying queries being non const

886

Typo arugments

890–893

Should move this to AttributeFuncs? Is there any useful case where this differs from areInlineCompatible?

898

Should at least check the ABI attributes

arsenm added inline comments.Sep 12 2023, 4:25 AM
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
815

I'd assume no

816

I'd assume no. Do we even allow unsized parameters?

zixuan-wu edited reviewers, added: zixuan-wu; removed: Zeson.Sep 13 2023, 8:29 PM