hanchenye-llvm-project/llvm/lib
Craig Topper 171732aeb3 [X86] Add custom isel to select ADD/SUB/OR/XOR/AND to their non-immediate forms under optsize when the immediate has additional users.
Summary:
We attempt to prevent folding immediates with multiple users under optsize. But we only do this from store nodes and X86ISD::ADD/SUB/XOR/OR/AND patterns. We don't do it for ISD::ADD/SUB/XOR/OR/AND even though we count them as users when deciding whether to fold into other nodes. This leads to situations where we block folding to a compare for example, but still fold into an AND or OR as seen in PR27202.

Unfortunately touching the isel patterns in tablegen for the ISD::ADD/SUB/XOR/OR/AND opcodes will cause the patterns to be unusable for fast isel. And we don't have a way to make a fast isel only pattern.

To workaround this, this patch adds custom isel in front of the isel table that will select the non-immediate forms if the immediate has additional users. This may create some issues for ANDN and NOT matching. And there's room for improvement with unsigned 32 immediates on 64-bit AND.

This patch needs more thorough test cases, but I wanted to get feedback on the direction. Please send me any other test cases you've seen in the wild.

I think we probably have the same issue with the immediate matching when we fold RMW from X86ISD::ADD/SUB/XOR/OR/AND. And our TEST immedaite shrinking logic. Our cost modeling for immediates that can fit in a sign extended 8-bit immediate on a 16/32/64 bit operation is completely wrong.

I also wonder if we should update the ConstantHoisting cost model and block folding for "opaque" constants. But of course constants can still be created by DAG combine and lowering optimizations.

Fixes PR27202

Reviewers: spatel, RKSimon, andreadb

Reviewed By: RKSimon

Subscribers: jsji, hiraditya, jdoerfert, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59909

llvm-svn: 365163
2019-07-04 22:53:57 +00:00
..
Analysis Revert [ThinLTO] Optimize writeonly globals out 2019-07-04 00:03:30 +00:00
AsmParser Revert [ThinLTO] Optimize writeonly globals out 2019-07-04 00:03:30 +00:00
BinaryFormat [WebAssembly] Fix list of relocations with addends in lld 2019-06-26 00:52:42 +00:00
Bitcode Fix -Wdocumentation param warning. 2019-07-04 10:35:31 +00:00
Bitstream [Bitcode] Move Bitstream to a separate library 2019-07-03 22:40:07 +00:00
CodeGen [DAGCombiner] Don't combine (addcarry (uaddo X, Y), 0, Carry) -> (addcarry X, Y, Carry) if the Carry comes from the uaddo. 2019-07-04 18:18:46 +00:00
DebugInfo Revert Changing CodeView debug info type record representation in assembly files to make it more human-readable & editable 2019-07-03 00:51:49 +00:00
Demangle llvm-undname: Correctly demangle vararg parameters 2019-06-04 19:10:08 +00:00
ExecutionEngine [JITLink][ORC] Add EHFrameRegistrar interface, use in EHFrameRegistrationPlugin. 2019-07-04 00:05:12 +00:00
FuzzMutate
Fuzzer
IR Revert [ThinLTO] Optimize writeonly globals out 2019-07-04 00:03:30 +00:00
IRReader [IRReader] Expose getLazyIRModule 2019-02-11 22:01:13 +00:00
LTO Revert [ThinLTO] Optimize writeonly globals out 2019-07-04 00:03:30 +00:00
LineEditor [CMake] Delete redundant DEPENDS/LINK_LIBS from LineEditor/XRay 2019-06-22 01:50:21 +00:00
Linker Reapply: IR: add optional type to 'byval' function parameters 2019-05-30 18:48:23 +00:00
MC Add support for the 'macCatalyst' MachO platform 2019-07-02 23:47:11 +00:00
MCA [MCA] Ignore invalid processor resource writes of zero cycles. NFCI 2019-06-14 13:31:21 +00:00
Object [MachO] Add valid architecture function 2019-07-04 00:17:02 +00:00
ObjectYAML [yaml2obj] - Allow overriding sh_offset field from the YAML. 2019-07-02 10:20:12 +00:00
Option Make AddLastArg() variadic and use it more. No behavior change. 2019-06-26 17:51:47 +00:00
Passes [clang][NewPM] Do not eliminate available_externally durng `-O2 -flto` runs 2019-06-20 19:44:51 +00:00
ProfileData Cleanup: llvm::bsearch -> llvm::partition_point after r364719 2019-06-30 11:19:56 +00:00
Remarks Fix MSVC "not all control paths return a value" warnings. NFCI. 2019-07-04 09:46:06 +00:00
Support Remove some autoconf references from docs and comments 2019-07-03 09:57:59 +00:00
TableGen TableGen: Handle nontrivial foreach range bounds 2019-05-22 21:28:20 +00:00
Target [X86] Add custom isel to select ADD/SUB/OR/XOR/AND to their non-immediate forms under optsize when the immediate has additional users. 2019-07-04 22:53:57 +00:00
Testing [Testing] Move clangd::Annotations to llvm testing support 2019-04-25 10:08:31 +00:00
TextAPI Cleanup: llvm::bsearch -> llvm::partition_point after r364719 2019-06-30 11:19:56 +00:00
ToolDrivers Share /machine: handling code with llvm-cvtres too 2019-06-12 11:32:43 +00:00
Transforms [InstCombine] allow undef elements when forming splat from chain of insertelements 2019-07-04 16:45:34 +00:00
WindowsManifest
XRay [CMake] Delete redundant DEPENDS/LINK_LIBS from LineEditor/XRay 2019-06-22 01:50:21 +00:00
CMakeLists.txt [Bitcode] Move Bitstream to a separate library 2019-07-03 22:40:07 +00:00
LLVMBuild.txt [Bitcode] Move Bitstream to a separate library 2019-07-03 22:40:07 +00:00