aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/CodeGen
AgeCommit message (Collapse)AuthorFilesLines
45 hours[CodeGen][test] Fix Buildbot failure due to uninitialized variables (#161085)A. Jiang1-1/+1
Under some options used by LLVM Buildbot, an uninitialized variable (recently added to the test suite) caused constant evaluation failure, despite the type of that variable is an empty class. This PR explicitly initializes the variables with `{}` to fix the error. Follows-up a558d656043734cc4d02e0a0a12e4c308c28f8c7.
45 hoursReland "[DebugInfo][DwarfDebug] Separate creation and population of abstract ↵Vladislav Dzhidzhoev3-16/+36
subprogram DIEs" (#160786) This is an attempt to reland https://github.com/llvm/llvm-project/pull/159104 with the fix for https://github.com/llvm/llvm-project/issues/160197. The original patch had the following problem: when an abstract subprogram DIE is constructed from within `DwarfDebug::endFunctionImpl()`, `DwarfDebug::constructAbstractSubprogramScopeDIE()` acknowledges `unit:` field of DISubprogram. But an abstract subprogram DIE constructed from `DwarfDebug::beginModule()` was put in the same compile unit to which global variable referencing the subprogram belonged, regardless of subprogram's `unit:`. This is fixed by adding `DwarfDebug::getOrCreateAbstractSubprogramCU()` used by both`DwarfDebug:: constructAbstractSubprogramScopeDIE()` and `DwarfCompileUnit::getOrCreateSubprogramDIE()` when abstract subprogram is queried during the creation of DIEs for globals in `DwarfDebug::beginModule()`. The fix and the already-reviewed code from https://github.com/llvm/llvm-project/pull/159104 are two separate commits in this PR. ===== The original commit message follows: With this change, construction of abstract subprogram DIEs is split in two stages/functions: creation of DIE (in DwarfCompileUnit::getOrCreateAbstractSubprogramDIE) and its population with children (in DwarfCompileUnit::constructAbstractSubprogramScopeDIE). With that, abstract subprograms can be created/referenced from DwarfDebug::beginModule, which should solve the issue with static local variables DIE creation of inlined functons with optimized-out definitions. It fixes https://github.com/llvm/llvm-project/issues/29985. LexicalScopes class now stores mapping from DISubprograms to their corresponding llvm::Function's. It is supposed to be built before processing of each function (so, now LexicalScopes class has a method for "module initialization" alongside the method for "function initialization"). It is used by DwarfCompileUnit to determine whether a DISubprogram needs an abstract DIE before DwarfDebug::beginFunction is invoked. DwarfCompileUnit::getOrCreateSubprogramDIE method is added, which can create an abstract or a concrete DIE for a subprogram. It accepts llvm::Function* argument to determine whether a concrete DIE must be created. This is a temporary fix for https://github.com/llvm/llvm-project/issues/29985. Ideally, it will be fixed by moving global variables and types emission to DwarfDebug::endModule (https://reviews.llvm.org/D144007, https://reviews.llvm.org/D144005). Some code proposed by Ellis Hoag <ellis.sparky.hoag@gmail.com> in https://github.com/llvm/llvm-project/pull/90523 was taken for this commit.
3 days[CodeGen] Get rid of incorrect `std` template specializations (#160804)A. Jiang1-0/+35
This patch renames comparators - from `std::equal_to<llvm::rdf::RegisterRef>` to `llvm::rdf::RegisterRefEqualTo`, and - from `std::less<llvm::rdf::RegisterRef>` to `llvm::rdf::RegisterRefLess`. The original specializations don't satisfy the requirements for the original `std` templates by being stateful and non-default-constructible, so they make the program have UB due to C++17 [namespace.std]/2, C++20/23 [namespace.std]/5. > A program may explicitly instantiate a class template defined in the standard library only if the declaration > - depends on the name of at least one program-defined type, and > - the instantiation meets the standard library requirements for the original template.
8 daysRevert "[DebugInfo][DwarfDebug] Separate creation and population of abstract ↵Vladislav Dzhidzhoev3-36/+16
subprogram DIEs" (#160349) Reverts llvm/llvm-project#159104 due to the issues reported in https://github.com/llvm/llvm-project/issues/160197.
12 days[llvm][test][CGPluginTest] Add back missing TargetParser dependency (#159760)Raul Tambre1-0/+1
Din't seem to be used, but is. [737/738] Linking CXX executable unittests/CodeGen/CGPluginTest/CGPluginTest FAILED: unittests/CodeGen/CGPluginTest/CGPluginTest : && /usr/bin/c++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-array-bounds -Wno-stringop-overread -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,--export-dynamic -Wl,--gc-sections unittests/CodeGen/CGPluginTest/CMakeFiles/CGPluginTest.dir/PluginTest.cpp.o unittests/CodeGen/CGPluginTest/CMakeFiles/CGPluginTest.dir/Plugin/CodeGenTestPass.cpp.o -o unittests/CodeGen/CGPluginTest/CGPluginTest -Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/lib lib/libLLVMX86CodeGen.so.22.0git lib/libLLVMX86AsmParser.so.22.0git lib/libLLVMX86De sc.so.22.0git lib/libLLVMX86Disassembler.so.22.0git lib/libLLVMX86Info.so.22.0git lib/libLLVMAMDGPUCodeGen.so.22.0git lib/libLLVMAMDGPUAsmParser.so.22.0git lib/libLLVMAMDGPUDisassembler.so.22.0git lib/libllvm_gtest_main.so.22.0git lib/libLLVMTestingSupport.so.22.0git lib/libLLVMCodeGen.so.22.0git lib/libLLVMTarget.so.22.0git lib/libLLVMAMDGPUDesc.so.22.0git lib/libLLVMAMDGPUInfo.so.22.0git lib/libLLVMAMDGPUUtils.so.22.0git lib/libLLVMCore.so.22.0git lib/libLLVMMC.so.22.0git lib/libllvm_gtest.so.22.0git lib/libLLVMSupport.so.22.0git -Wl,-rpath-link,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/lib && : /usr/bin/ld: unittests/CodeGen/CGPluginTest/CMakeFiles/CGPluginTest.dir/PluginTest.cpp.o: undefined reference to symbol '_ZN4llvm6TripleC1ERKNS_5TwineES3_S3_' Fixes: 4e1c996674cc340f290b0a528e2038e76494d8d4
12 days[llvm][test][CGPluginTest] Keep plugin in shared library directoryRaul Tambre3-24/+5
Scoping to the root build directory instead of using the path directly is awkward and the only such occurrence in the test suite. It's also prone to breakage for downstreams that change the library path. But it's not even necessary: during build we have the appropriate RPATHs set so we can just depend on the dynamic loader to find it. This extra logic is probably just copy-paste from PluginsTest.cpp. Additionally: * Removed TargetParser as a dependency because it doesn't seem to actually be used. * Moved `add_dependencies()` to `DEPENDS` to better match the rest of LLVM.
14 days[DebugInfo][DwarfDebug] Separate creation and population of abstract ↵Vladislav Dzhidzhoev3-16/+36
subprogram DIEs (#159104) With this change, construction of abstract subprogram DIEs is split in two stages/functions: creation of DIE (in DwarfCompileUnit::getOrCreateAbstractSubprogramDIE) and its population with children (in DwarfCompileUnit::constructAbstractSubprogramScopeDIE). With that, abstract subprograms can be created/referenced from DwarfDebug::beginModule, which should solve the issue with static local variables DIE creation of inlined functons with optimized-out definitions. It fixes https://github.com/llvm/llvm-project/issues/29985. LexicalScopes class now stores mapping from DISubprograms to their corresponding llvm::Function's. It is supposed to be built before processing of each function (so, now LexicalScopes class has a method for "module initialization" alongside the method for "function initialization"). It is used by DwarfCompileUnit to determine whether a DISubprogram needs an abstract DIE before DwarfDebug::beginFunction is invoked. DwarfCompileUnit::getOrCreateSubprogramDIE method is added, which can create an abstract or a concrete DIE for a subprogram. It accepts llvm::Function* argument to determine whether a concrete DIE must be created. This is a temporary fix for https://github.com/llvm/llvm-project/issues/29985. Ideally, it will be fixed by moving global variables and types emission to DwarfDebug::endModule (https://reviews.llvm.org/D144007, https://reviews.llvm.org/D144005). Some code proposed by Ellis Hoag <ellis.sparky.hoag@gmail.com> in https://github.com/llvm/llvm-project/pull/90523 was taken for this commit.
2025-09-15[GlobalISel] Remove GI known bits cache (#157352)David Green2-2/+2
There is a cache on the known-bit computed by global-isel. It only works inside a single query to computeKnownBits, which limits its usefulness, and according to the tests can sometimes limit the effectiveness of known-bits queries. (Although some AMD tests look longer). Keeping the cache valid and clearing it at the correct times can also require being careful about the functions called inside known-bits queries. I measured compile-time of removing it and came up with: ``` 7zip 2.06405E+11 2.06436E+11 0.015018992 Bullet 1.01298E+11 1.01186E+11 -0.110236169 ClamAV 57942466667 57848066667 -0.16292023 SPASS 45444466667 45402966667 -0.091320249 consumer 35432466667 35381233333 -0.144594317 kimwitu++ 40858833333 40927933333 0.169118877 lencod 70022366667 69950633333 -0.102443457 mafft 38439900000 38413233333 -0.069372362 sqlite3 35822266667 35770033333 -0.145812474 tramp3d 82083133333 82045600000 -0.045726 Average -0.068828739 ``` The last column is % difference between with / without the cache. So in total it seems to be costing slightly more to keep the current known-bits cache than if it was removed. (Measured in instruction count, similar to llvm-compile-time-tracker). The hit rate wasn't terrible - higher than I expected. In the llvm-test-suite+external projects it was hit 4791030 times out of 91107008 queries, slightly more than 5%. Note that as globalisel increases in complexity, more known bits calls might be made and the numbers might shift. If that is the case it might be better to have a cache that works across calls, providing it doesn't make effectiveness worse.
2025-09-09MC: Use Triple form of lookupTarget in more places (#157591)Matt Arsenault1-1/+2
2025-09-08CodeGen: Make TargetInstrInfo constructor protected (#157336)Matt Arsenault1-1/+6
2025-08-23[CodeGen] Remove an obsolete macro test (NFC) (#155069)Kazu Hirata1-3/+0
We can drop the macro test because we require C++17 and GCC 7.4 these days. Note that std::is_trivially_copyable_v is a C++17 feature.
2025-08-20[AArch64][GlobalISel] Port unmerge KnownBits tests to ↵David Green1-45/+0
print<gisel-value-tracking>. NFC This takes the known-bits tests added in #112172 and ports them over to be a new print<gisel-value-tracking> test.
2025-08-12[MIR] Remove std::variant from multiple save/restore point handling [nfc] ↵Philip Reames1-14/+14
(#153226) In review of bbde6b, I had originally proposed that we support the legacy text format. As review evolved, it bacame clear this had been a bad idea (too much complexity), but in order to let that patch finally move forward, I approved the change with the variant. This change undoes the variant, and updates all the tests to just use the array form.
2025-08-08Revert "[AMDGPU] SelectionDAG divergence tracking should take into account ↵David Stuttard1-6/+1
Target divergency. (#147560)" (#152548) This reverts commit 9293b65a616b8de432a654d046e802540b146372.
2025-08-04[GlobalISel] Add constant matcher for APInt (#151357)jyli01161-0/+40
Changed m_SpecificICst, m_SpecificICstSplat and m_SpecificICstorSplat to match against APInt as well.
2025-08-01Add m_SelectCCLike matcher to match SELECT_CC or SELECT with SETCC (#149646)黃國庭1-0/+32
Fix #147282 and Follow-up to #148834 --------- Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-07-30[GISel] Introduce MIFlags::InBounds (#150900)Fabian Ritter1-2/+2
This flag applies to G_PTR_ADD instructions and indicates that the operation implements an inbounds getelementptr operation, i.e., the pointer operand is in bounds wrt. the allocated object it is based on, and the arithmetic does not change that. It is set when the IRTranslator lowers inbounds GEPs (currently only in some cases, to be extended with a future PR), and in the (build|materialize)ObjectPtrOffset functions. Inbounds information is useful in ISel when we have instructions that perform address computations whose intermediate steps must be in the same memory region as the final result. A follow-up patch will start using it for AMDGPU's flat memory instructions, where the immediate offset must not affect the memory aperture of the address. This is analogous to a concurrent effort in SDAG: #131862 (related: #140017, #141725). For SWDEV-516125.
2025-07-30[LLVM][SelectionDAG] Align poison/undef binop folds with IR. (#149334)Paul Walker5-185/+421
The "at construction" binop folds in SelectionDAG::getNode() has different behaviour when compared to the equivalent LLVM IR. This PR makes the behaviour consistent while also extending the coverage to include signed/unsigned max/min operations.
2025-07-29[GISel] Introduce MachineIRBuilder::(build|materialize)ObjectPtrOffset (#150392)Fabian Ritter1-2/+2
These functions are for building G_PTR_ADDs when we know that the base pointer and the result are both valid pointers into (or just after) the same object. They are similar to SelectionDAG::getObjectPtrOffset. This PR also changes call sites of the generic (build|materialize)PtrAdd functions that implement pointer arithmetic to split large memory accesses to the new functions. Since memory accesses have to fit into an object in memory, pointer arithmetic to an offset into a large memory access also yields an address in that object. Currently, these (build|materialize)ObjectPtrOffset functions only add "nuw" to the generated G_PTR_ADD, but I intend to introduce an "inbounds" MIFlag in a later PR (analogous to a concurrent effort in SDAG: #131862, related: #140017, #141725) that will also be set in the (build|materialize)ObjectPtrOffset functions. Most test changes just add "nuw" to G_PTR_ADDs. Exceptions are AMDGPU's call-outgoing-stack-args.ll, flat-scratch.ll, and freeze.ll tests, where offsets are now folded into scratch instructions, and cases where the behavior of the check regeneration script changed, resulting, e.g., in better checks for "nusw G_PTR_ADD" instructions, matched empty lines, and the use of "CHECK-NEXT" in MIPS tests. For SWDEV-516125.
2025-07-26[CodeGen] Remove an unnecessary cast (NFC) (#150784)Kazu Hirata1-2/+1
createTargetMachine() already returns TargetMachine *.
2025-07-18[DebugInfo] Suppress lots of users of DbgValueInst (#149476)Jeremy Morse1-1/+1
This is another prune of dead code -- we never generate debug intrinsics nowadays, therefore there's no need for these codepaths to run. --------- Co-authored-by: Nikita Popov <github@npopov.com>
2025-07-10Reland "[CodeGen] Expose the extensibility of PassConfig to plugins (#139059)"Tcc1007-0/+236
Add missing dependencies to unittest target Original patch broke BUILD_SHARED bots and required revert #147947
2025-07-10Revert "[CodeGen] Expose the extensibility of PassConfig to plugins" (#147947)Jan Patrick Lehr7-234/+0
Reverts llvm/llvm-project#139059 This broke https://lab.llvm.org/buildbot/#/builders/10/builds/9125/steps/8/logs/stdio The bot does a SHARED_LIBS=ON build. I can reproduce locally with the CMake cache file in offload/cmake/caches/AMDGPUBot.cmake as the build config.
2025-07-10[CodeGen] Expose the extensibility of PassConfig to plugins (#139059)Tcc1007-0/+234
This PR exposes the backend pass config to plugins via a callback. Plugin authors can register a callback that is being triggered before the target backend adds their passes to the pipeline. In the callback they then get access to the `TargetMachine`, the `PassManager`, and the `TargetPassConfig`. This allows plugins to call `TargetPassConfig::insertPass`, which is honored in the subsequent `addPass` of the main backend. We implemented this using the legacy pass manager since backends still use it as the default.
2025-07-09[AMDGPU] SelectionDAG divergence tracking should take into account Target ↵alex-t2-2/+12
divergency. (#147560) This is the next attempt to upstream this: https://github.com/llvm/llvm-project/pull/144947 The las one caused build errors in AArch64. Issue was resolved.
2025-07-08[DAG] SDPatternMatch - add matching for SELECT_CC patterns to min/max like ↵Simon Pilgrim1-0/+33
matchers (#147071) Fixes #147083
2025-07-07[NFC] Remove redundant namespace qualifier in SelectionDAGPatternMatchTest ↵woruyu1-1/+1
(#147443) ### Summary This PR remove the extra llvm::SDPatternMatch prefix in https://github.com/llvm/llvm-project/pull/147044
2025-07-07[DAG] SDPatternMatch m_Zero/m_One/m_AllOnes have inconsistent undef h… ↵woruyu1-0/+86
(#147044) ### Summary This PR resolves https://github.com/llvm/llvm-project/issues/146871 This PR resolves https://github.com/llvm/llvm-project/issues/140745 Refactor m_Zero/m_One/m_AllOnes all use struct template function to match and AllowUndefs=false as default.
2025-07-03Revert "[AMDGPU] SelectionDAG divergence tracking should take into account ↵Florian Hahn2-12/+2
Target divergency. (#144947)" This reverts commit 8ac7210b7f0ad49ae7809bf6a9faf2f7433384b0. This breaks the building the AArch64 backend, e.g. see https://github.com/llvm/llvm-project/pull/144947 Revert to unbreak the build. Also reverts follow-up commits 1e76f012db3ccfaa05e238812e572b5b6d12c17e.
2025-07-03[AMDGPU] SelectionDAG divergence tracking should take into account Target ↵alex-t2-2/+12
divergency. (#144947) If a kernel is known to be executing only a single lane, IR UniformityAnalysis will take note of that (via GCNTTIImpl::hasBranchDivergence) and report that all values are uniform. SelectionDAG's built-in divergence tracking should do the same.
2025-06-30[DAG] Implement SDPatternMatch `m_SpecificScalarVT` and ↵zhaohui1-0/+8
`m_SpecificVectorElementVT` matchers (#144996) Resolves https://github.com/llvm/llvm-project/issues/144477 --------- Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-06-26[DAG] Add `SDPatternMatch::m_Load` (#145481)Abhishek Kaushik1-0/+13
Add SDPatternMatch matcher and unit test coverage for `ISD::LOAD` opcode. This only matches the loaded value i.e. ResNo 0 and not the output chain. e.g. ``` m_Load(m_Value(), m_Value(), m_Value()) ``` The first value is the input chain, the second is the base pointer, and the last value is the offset.
2025-06-26[DAG] Add SDPatternMatch::m_Result to match a specific SDValue result (#145775)Min-Yih Hsu1-0/+14
`m_Result<N>` matches a SDValue that is the N-th result of the defining SDNode. This is useful for creating a more fine-grained matching on SDNode with multiple results. ----- Inspired by #145481
2025-06-20[SDPatternMatch] Add m_Poison matcher (#144860)Ming Yan1-0/+5
Add SDPatternMatch matcher and unit test coverage for ISD::POISON opcode e.g. ``` m_InsertElt(m_Poison(), m_Value(), m_Zero()) ```
2025-06-18[DAG] Implement SDPatternMatch `m_Abs()` matcher (#144512)Rajveer Singh Bharadwaj1-0/+4
2025-06-12[GISel] KnownFPClass ValueTracking fix handling of vectors (#143372)Tim Gymnich1-0/+98
2025-06-08[llvm] Compare std::optional<T> to values directly (NFC) (#143340)Kazu Hirata1-1/+1
This patch transforms: X && *X == Y to: X == Y where X is of std::optional<T>, and Y is of T or similar.
2025-05-28[llvm] annotate interfaces in llvm/CGData and llvm/CodeGen for DLL export ↵Andrew Rogers1-5/+6
(#140823) ## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/CGData` and `llvm/CodeGen` libraries. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). The bulk of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. The following manual adjustments were also applied after running IDS on Linux: - Add `LLVM_ABI` to a subset of private class methods and fields that require export - Add `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE` to exported instantiated templates defined via X-macro - Add `LLVM_ABI_FRIEND` to friend member functions declared with `LLVM_ABI` - Explicitly make classes non-copyable where needed to due IDS adding LLVM_ABI at the class level - Add `#include "llvm/Support/Compiler.h"` to files where it was not auto-added by IDS due to no pre-existing block of include statements. - Add `LLVM_ABI` to a small number of symbols that require export but are not declared in headers ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
2025-05-28[AArch64] TableGen-erate SDNode descriptions (#140472)Benjamin Maxwell2-863/+0
This continues s-barannikov's work TableGen-erating SDNode descriptions. This takes the initial patch from #119709 and moves documentation and the rest of the AArch64ISD nodes to TableGen. Some issues were found by the generated SDNode verification added in this patch. These issues have been described and fixed in the following PRs: - #140706 - #140711 - #140713 - #140715 --------- Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
2025-05-26[LLVM] [NFC] - Remove duplicate #include headers from the files of llvm dir ↵Akash Agrawal1-2/+0
(#141057) A few files of llvm dir had duplicate headers included. This patch removes those redundancies. --------- Co-authored-by: Akash Agrawal <akashag@qti.qualcomm.com>
2025-05-23[GISel] Add KnownFPClass Analysis to GISelValueTrackingPass (#134611)Tim Gymnich2-0/+1063
- add KnownFPClass analysis to GISelValueTrackingPass - add MI pattern for `m_GIsFPClass`
2025-05-14[GlobalISel] Add a GISelValueTracker printing pass (#139687)David Green1-46/+0
This adds a GISelValueTrackingPrinterPass that can print the known bits and sign bit of each def in a function. It is built on the new pass manager and so adds a NPM GISelValueTrackingAnalysis, renaming the older class to GISelValueTrackingAnalysisLegacy. The first 2 functions from the AArch64GISelMITest are ported over to an mir test to show it working. It also runs successfully on all files in llvm/test/CodeGen/AArch64/GlobalISel/*.mir that are not invalid. It can hopefully be used to test GlobalISel known bits analysis more directly in common cases, without jumping through the hoops that the C++ tests requires.
2025-05-14[GC] Use `MapVector` for `GCStrategyMap` (#132729)paperchalice2-0/+77
Use `MapVector` so `GCStrategyMap` can support forward and reverse iterator, which is required in `AsmPrinter`.
2025-05-13[GlobalISel] Add computeNumSignBits for G_BUILD_VECTOR. (#139506)David Green1-1/+1
The code is similar to SelectionDAG::ComputeNumSignBits, but does not deal with truncating buildvectors.
2025-05-06[DAG] Add SDPatternMatch::m_BitwiseLogic common matcher for AND/OR/XOR nodes ↵Simon Pilgrim1-0/+5
(#138301)
2025-05-05[CodeGen] Fix warningsKazu Hirata1-2/+2
This patch fixes: third-party/unittest/googletest/include/gtest/gtest.h:1379:11: error: comparison of integers of different signs: 'const unsigned long' and 'const int' [-Werror,-Wsign-compare]
2025-05-05[GlobalISel] Take the result size into account when const folding icmp (#134365)KRM71-0/+45
The current implementation always creates a 1 bit constant for the result of the `G_ICMP`, which will cause issues if the destination register size is larger than that. With asserts enabled, it will cause a crash in `buildConstant`: ``` llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp:322: virtual MachineInstrBuilder llvm::MachineIRBuilder::buildConstant(const DstOp &, const ConstantInt &): Assertion `EltTy.getScalarSizeInBits() == Val.getBitWidth() && "creating constant with the wrong size"' failed. ```
2025-04-05[X86][Test] Reorder PassMgrF and OS. (#134481)weiwei chen1-1/+2
Reordering `OS` and `PassMgrF` should fix the asan failure that's caused by OS being destroyed before `PassMgrF` deletes the AsmPrinter. As shown in[ this asan run ](https://lab.llvm.org/buildbot/#/builders/52/builds/7340/steps/12/logs/stdio) ``` This frame has 15 object(s): [32, 48) 'PassMgrF' (line 154) [64, 1112) 'Buf' (line 155) [1248, 1304) 'OS' (line 156) <== Memory access at offset 1280 is inside this variable ``` which indicates an ordering problem. This should help to fix all the sanitizer failures caused by the test `X86MCInstLowerTest.cpp` that's introduced by [this PR](https://github.com/llvm/llvm-project/pull/133352#issuecomment-2780173791).
2025-04-04[X86Backend][M68KBackend] Make Ctx in X86MCInstLower (M68KInstLower) the ↵weiwei chen2-0/+175
same as AsmPrinter.OutContext (#133352) In `X86MCInstLower::LowerMachineOperand`, a new `MCSymbol` can be created in `GetSymbolFromOperand(MO)` where `MO.getType()` is `MachineOperand::MO_ExternalSymbol` ``` case MachineOperand::MO_ExternalSymbol: return LowerSymbolOperand(MO, GetSymbolFromOperand(MO)); ``` at https://github.com/llvm/llvm-project/blob/725a7b664b92cd2e884806de5a08900b43d43cce/llvm/lib/Target/X86/X86MCInstLower.cpp#L196 However, this newly created symbol will not be marked properly with its `IsExternal` field since `Ctx.getOrCreateSymbol(Name)` doesn't know if the newly created `MCSymbol` is for `MachineOperand::MO_ExternalSymbol`. Looking at other backends, for example `Arch64MCInstLower` is doing for handling `MC_ExternalSymbol` https://github.com/llvm/llvm-project/blob/14c36db16fc090ef494ff6d8207562c414b40e30/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp#L366-L367 https://github.com/llvm/llvm-project/blob/14c36db16fc090ef494ff6d8207562c414b40e30/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp#L145-L148 It creates/gets the MCSymbol from `AsmPrinter.OutContext` instead of from `Ctx`. Moreover, `Ctx` for `AArch64MCLower` is the same as `AsmPrinter.OutContext`. https://github.com/llvm/llvm-project/blob/8e7d6baf0e013408be932758b4a5334c14a34086/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp#L100. This applies to almost all the other backends except X86 and M68k. ``` $git grep "MCInstLowering(" lib/Target/AArch64/AArch64AsmPrinter.cpp:100: : AsmPrinter(TM, std::move(Streamer)), MCInstLowering(OutContext, *this), lib/Target/AMDGPU/AMDGPUMCInstLower.cpp:223: AMDGPUMCInstLower MCInstLowering(OutContext, STI, *this); lib/Target/AMDGPU/AMDGPUMCInstLower.cpp:257: AMDGPUMCInstLower MCInstLowering(OutContext, STI, *this); lib/Target/AMDGPU/R600MCInstLower.cpp:52: R600MCInstLower MCInstLowering(OutContext, STI, *this); lib/Target/ARC/ARCAsmPrinter.cpp:41: MCInstLowering(&OutContext, *this) {} lib/Target/AVR/AVRAsmPrinter.cpp:196: AVRMCInstLower MCInstLowering(OutContext, *this); lib/Target/BPF/BPFAsmPrinter.cpp:144: BPFMCInstLower MCInstLowering(OutContext, *this); lib/Target/CSKY/CSKYAsmPrinter.cpp:41: : AsmPrinter(TM, std::move(Streamer)), MCInstLowering(OutContext, *this) {} lib/Target/Lanai/LanaiAsmPrinter.cpp:147: LanaiMCInstLower MCInstLowering(OutContext, *this); lib/Target/Lanai/LanaiAsmPrinter.cpp:184: LanaiMCInstLower MCInstLowering(OutContext, *this); lib/Target/MSP430/MSP430AsmPrinter.cpp:149: MSP430MCInstLower MCInstLowering(OutContext, *this); lib/Target/Mips/MipsAsmPrinter.h:126: : AsmPrinter(TM, std::move(Streamer)), MCInstLowering(*this) {} lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp:695: WebAssemblyMCInstLower MCInstLowering(OutContext, *this); lib/Target/X86/X86MCInstLower.cpp:2200: X86MCInstLower MCInstLowering(*MF, *this); ``` This patch makes `X86MCInstLower` and `M68KInstLower` to have their `Ctx` from `AsmPrinter.OutContext` instead of getting it from `MF.getContext()` to be consistent with all the other backends. I think since normal use case (probably anything other than our un-conventional case) only handles one llvm module all the way through in the codegen pipeline till the end of code emission (AsmPrint), `AsmPrinter.OutContext` is the same as MachineFunction's MCContext, so this change is an NFC. ---- This fixes an error while running the generated code in ORC JIT for our use case with [MCLinker](https://youtu.be/yuSBEXkjfEA?si=HjgjkxJ9hLfnSvBj&t=813) (see more details below): https://github.com/llvm/llvm-project/pull/133291#issuecomment-2759200983 We (Mojo) are trying to do a MC level linking so that we break llvm module into multiple submodules to compile and codegen in parallel (technically into *.o files with symbol linkage type change), but instead of archive all of them into one `.a` file, we want to fix the symbol linkage type and still produce one *.o file. The parallel codegen pipeline generates the codegen data structures in their own `MCContext` (which is `Ctx` here). So if function `f` and `g` got split into different submodules, they will have different `Ctx`. And when we try to create an external symbol with the same name for each of them with `Ctx.getOrCreate(SymName)`, we will get two different `MCSymbol*` because `f` and `g`'s `MCContext` are different and they can't see each other. This is unfortunately not what we want for external symbols. Using `AsmPrinter.OutContext` helps, since it is shared, if we try to get or create the `MCSymbol` there, we'll be able to deduplicate.
2025-03-29[GlobalISel][NFC] Rename GISelKnownBits to GISelValueTracking (#133466)Tim Gymnich3-133/+133
- rename `GISelKnownBits` to `GISelValueTracking` to analyze more than just `KnownBits` in the future