aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/ExpandMemCmp.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-01-03[ExpandMemCmp] Recognize canonical form of (icmp sle/sge X, 0) in ↵Craig Topper1-0/+8
getMemCmpOneBlock. (#121540) This code recognizes special cases where the result of memcmp is compared with 0. If the compare is sle/sge, then InstCombine canonicalizes to (icmp slt X, 1) or (icmp sgt X, -1). We should recognize those patterns too.
2025-01-03[ExpandMemCmp] Use m_SpecificInt to simplify code. NFC (#121532)Craig Topper1-3/+3
2025-01-03[ExpandMemCmp][AArch64][PowerPC][RISCV][X86] Use llvm.ucmp instead of (sub ↵Craig Topper1-11/+3
(zext (icmp ugt)), (zext (icmp ult))). (#121530) AArch64 and PowerPC look like a improvements. RISC-V is neutral. X86 trades a dependency breaking xor before a seta for a movsx after a sbbb. Depending on how the result is used, this movsx might go away.
2024-12-13PatternMatch: migrate to CmpPredicate (#118534)Ramkumar Ramachandra1-1/+1
With the introduction of CmpPredicate in 51a895a (IR: introduce struct with CmpInst::Predicate and samesign), PatternMatch is one of the first key pieces of infrastructure that must be updated to match a CmpInst respecting samesign information. Implement this change to Cmp-matchers. This is a preparatory step in migrating the codebase over to CmpPredicate. Since we no functional changes are desired at this stage, we have chosen not to migrate CmpPredicate::operator==(CmpPredicate) calls to use CmpPredicate::getMatching(), as that would have visible impact on tests that are not yet written: instead, we call CmpPredicate::operator==(Predicate), preserving the old behavior, while also inserting a few FIXME comments for follow-ups.
2024-11-20IR: de-duplicate two CmpInst routines (NFC) (#116866)Ramkumar Ramachandra1-1/+1
De-duplicate the functions getSignedPredicate and getUnsignedPredicate, nearly identical versions of which were present in CmpInst and ICmpInst, creating less confusion.
2024-10-28Check hasOptSize() in shouldOptimizeForSize() (#112626)Ellis Hoag1-2/+1
2024-10-11[NFC] Rename `Intrinsic::getDeclaration` to `getOrInsertDeclaration` (#111752)Rahul Joshi1-1/+1
Rename the function to reflect its correct behavior and to be consistent with `Module::getOrInsertFunction`. This is also in preparation of adding a new `Intrinsic::getDeclaration` that will have behavior similar to `Module::getFunction` (i.e, just lookup, no creation).
2024-08-12[ExpandMemCmp] Use getAllOnesValue()Nikita Popov1-1/+1
Split out from https://github.com/llvm/llvm-project/pull/80309.
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov1-1/+1
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
2024-06-24Revert "[IR][NFC] Update IRBuilder to use InsertPosition (#96497)"Stephen Tozer1-3/+3
Reverts the above commit, as it updates a common header function and did not update all callsites: https://lab.llvm.org/buildbot/#/builders/29/builds/382 This reverts commit 6481dc57612671ebe77fe9c34214fba94e1b3b27.
2024-06-24[IR][NFC] Update IRBuilder to use InsertPosition (#96497)Stephen Tozer1-3/+3
Uses the new InsertPosition class (added in #94226) to simplify some of the IRBuilder interface, and removes the need to pass a BasicBlock alongside a BasicBlock::iterator, using the fact that we can now get the parent basic block from the iterator even if it points to the sentinel. This patch removes the BasicBlock argument from each constructor or call to setInsertPoint. This has no functional effect, but later on as we look to remove the `Instruction *InsertBefore` argument from instruction-creation (discussed [here](https://discourse.llvm.org/t/psa-instruction-constructors-changing-to-iterator-only-insertion/77845)), this will simplify the process by allowing us to deprecate the InsertPosition constructor directly and catch all the cases where we use instructions rather than iterators.
2023-12-13[CodeGen] Port `ExpandMemCmp` to new pass manager (#74050)paperchalice1-28/+43
2023-11-09[ExpandMemCmp] Improve memcmp optimisation for boolean results (#71221)Igor Kirillov1-6/+45
This patch enhances the optimization of memcmp calls when only two outcomes are needed and comparison fits into one block, for example: bool result = memcmp(a, b, 6) > 0; Previously, LLVM would generate unnecessary operations even when the user of memcmp was only interested in a binary outcome.
2023-10-30[CodeGen] Improve ExpandMemCmp for more efficient non-register aligned sizes ↵Igor Kirillov1-20/+75
handling (#70469) * Enhanced the logic of ExpandMemCmp pass to merge contiguous subsequences in LoadSequence, based on sizes allowed in `AllowedTailExpansions`. * This enhancement seeks to minimize the number of basic blocks and produce optimized code when using memcmp with non-register aligned sizes. * Enable this feature for AArch64 with memcmp sizes modulo 8 equal to 3, 5, and 6. Reapplication of #69942 after fixing a bug
2023-10-27Revert "[CodeGen] Improve ExpandMemCmp for more efficient non-register ↵Igor Kirillov1-74/+19
aligned sizes handling (#69942)" This reverts commit 9bcb30d31813bbdea6b65789f64aed3f0e58d507.
2023-10-27[CodeGen] Improve ExpandMemCmp for more efficient non-register aligned sizes ↵Igor Kirillov1-19/+74
handling (#69942) * Enhanced the logic of ExpandMemCmp pass to merge contiguous subsequences in LoadSequence, based on sizes allowed in `AllowedTailExpansions`. * This enhancement seeks to minimize the number of basic blocks and produce optimized code when using memcmp with non-register aligned sizes. * Enable this feature for AArch64 with memcmp sizes modulo 8 equal to 3, 5, and 6.
2023-09-11[NFC][RemoveDIs] Use iterators over inst-pointers when using IRBuilderJeremy Morse1-1/+1
This patch adds a two-argument SetInsertPoint method to IRBuilder that takes a block/iterator instead of an instruction, and updates many call sites to use it. The motivating reason for doing this is given here [0], we'd like to pass around more information about the position of debug-info in the iterator object. That necessitates passing iterators around most of the time. [0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939 Differential Revision: https://reviews.llvm.org/D152468
2023-06-23[llvm] Replace use of Type::getPointerTo() (NFC)Youngsuk Kim1-8/+2
Partial progress towards replacing in-tree uses of `Type::getPointerTo()`. If `getPointerTo()` is used solely to support an unnecessary bitcast, remove the bitcast. Reviewed By: barannikov88, nikic Differential Revision: https://reviews.llvm.org/D153307
2023-04-17Fix uninitialized pointer members in CodeGenAkshay Khadse1-2/+2
This change initializes the members TSI, LI, DT, PSI, and ORE pointer feilds of the SelectOptimize class to nullptr. Reviewed By: LuoYuanke Differential Revision: https://reviews.llvm.org/D148303
2023-03-31[Coverity] Initialize pointer memeber.Luo, Yuanke1-2/+2
2022-11-26[CodeGen] Use std::optional in ExpandMemCmp.cpp (NFC)Kazu Hirata1-1/+2
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-21Don't use Optional::getPointer (NFC)Kazu Hirata1-2/+1
Since std::optional does not offer getPointer(), this patch replaces X.getPointer() with &*X to make the migration from llvm::Optional to std::optional easier. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Differential Revision: https://reviews.llvm.org/D138466
2022-06-20Don't use Optional::hasValue (NFC)Kazu Hirata1-1/+1
2022-04-15[ExpandMemCmp] Properly expand `bcmp` to an equality pattern.Clement Courbet1-3/+4
Before that change, constant-size `bcmp` would miss an opportunity to generate a more efficient equality pattern and would generate a -1/0-1 pattern instead. Differential Revision: https://reviews.llvm.org/D123849
2022-03-16Cleanup codegen includesserge-sans-paille1-1/+4
This is a (fixed) recommit of https://reviews.llvm.org/D121169 after: 1061034926 before: 1063332844 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121681
2022-03-10Revert "Cleanup codegen includes"Nico Weber1-4/+1
This reverts commit 7f230feeeac8a67b335f52bd2e900a05c6098f20. Breaks CodeGenCUDA/link-device-bitcode.cu in check-clang, and many LLVM tests, see comments on https://reviews.llvm.org/D121169
2022-03-10Cleanup codegen includesserge-sans-paille1-1/+4
after: 1061034926 before: 1063332844 Differential Revision: https://reviews.llvm.org/D121169
2022-01-30[CodeGen] Use default member initialization (NFC)Kazu Hirata1-4/+3
Identified with modernize-use-default-member-init.
2021-10-18[ExpandMemCmp] Update CFG before DTUNikita Popov1-2/+2
The applyUpdates() API requires that the CFG is already updated, so make sure to insert the new terminator first.
2021-01-30[ExpandMemCmpPass] Preserve Dominator Tree, if availableRoman Lebedev1-30/+75
This finishes getting rid of all the avoidable Dominator Tree recalculations in X86 optimized codegen pipeline.
2020-05-23TargetLowering.h - remove unnecessary TargetMachine.h include. NFCSimon Pilgrim1-0/+1
Replace with forward declaration and move dependency down to source files that actually need it. Both TargetLowering.h and TargetMachine.h are 2 of the most expensive headers (top 10) in the ClangBuildAnalyzer report when building llc.
2020-05-20Make Value::getPointerAlignment() return an Align, not a MaybeAlign.Eli Friedman1-2/+2
If we don't know anything about the alignment of a pointer, Align(1) is still correct: all pointers are at least 1-byte aligned. Included in this patch is a bugfix for an issue discovered during this cleanup: pointers with "dereferenceable" attributes/metadata were assumed to be aligned according to the type of the pointer. This wasn't intentional, as far as I can tell, so Loads.cpp was fixed to stop making this assumption. Frontends may need to be updated. I updated clang's handling of C++ references, and added a release note for this. Differential Revision: https://reviews.llvm.org/D80072
2020-04-15[CallSite removal][TargetLibraryInfo] Replace ImmutableCallSite with ↵Craig Topper1-1/+1
CallBase in one of the getLibFunc signatures. NFC Differential Revision: https://reviews.llvm.org/D78083
2020-03-16[ExpandMemCmp] Correctly set alignment of generated loadsJuneyoung Lee1-2/+6
Summary: This is a part of the series of efforts for correcting alignment of memory operations. (Another related bugs: https://bugs.llvm.org/show_bug.cgi?id=44388 , https://bugs.llvm.org/show_bug.cgi?id=44543 ) This fixes https://bugs.llvm.org/show_bug.cgi?id=43880 by giving default alignment of loads to 1. The test CodeGen/AArch64/bcmp-inline-small.ll should have been changed; it was introduced by https://reviews.llvm.org/D64805 . I talked with @evandro, and confirmed that the test is okay to be changed. Other two tests from PowerPC needed changes as well, but fixes were straightforward. Reviewers: courbet Reviewed By: courbet Subscribers: nlopes, gchatelet, wuzish, nemanjai, kristof.beyls, hiraditya, steven.zhang, danielkiss, llvm-commits, evandro Tags: #llvm Differential Revision: https://reviews.llvm.org/D76113
2020-03-09[ExpandMemCmp] Properly constant-fold all compares.Clement Courbet1-0/+4
Summary: This gets rid of duplicated code and diverging behaviour w.r.t. constants. Fixes PR45086. Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75519
2020-03-09[ExpandMemCmp] Properly constant-fold all compares.Clement Courbet1-98/+74
Summary: This gets rid of duplicated code and diverging behaviour w.r.t. constants. Fixes PR45086. Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75519
2020-03-03[ExpandMemCmp][NFC] Fix typo in comment.Clement Courbet1-1/+1
2019-12-09[PGO][PGSO] Instrument the code gen / target passes.Hiroshi Yamauchi1-11/+28
Summary: Split off of D67120. Add the profile guided size optimization instrumentation / queries in the code gen or target passes. This doesn't enable the size optimizations in those passes yet as they are currently disabled in shouldOptimizeForSize (for non-IR pass queries). A second try after reverted D71072. Reviewers: davidxl Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D71149
2019-12-06Revert "[PGO][PGSO] Instrument the code gen / target passes."Hiroshi Yamauchi1-28/+11
This reverts commit 9a0b5e14075a1f42a72eedb66fd4fde7985d37ac. This seems to break buildbots.
2019-12-06[PGO][PGSO] Instrument the code gen / target passes.Hiroshi Yamauchi1-11/+28
Summary: Split off of D67120. Add the profile guided size optimization instrumentation / queries in the code gen or target passes. This doesn't enable the size optimizations in those passes yet as they are currently disabled in shouldOptimizeForSize (for non-IR pass queries). Reviewers: davidxl Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D71072
2019-11-13Sink all InitializePasses.h includesReid Kleckner1-0/+1
This file lists every pass in LLVM, and is included by Pass.h, which is very popular. Every time we add, remove, or rename a pass in LLVM, it caused lots of recompilation. I found this fact by looking at this table, which is sorted by the number of times a file was changed over the last 100,000 git commits multiplied by the number of object files that depend on it in the current checkout: recompiles touches affected_files header 342380 95 3604 llvm/include/llvm/ADT/STLExtras.h 314730 234 1345 llvm/include/llvm/InitializePasses.h 307036 118 2602 llvm/include/llvm/ADT/APInt.h 213049 59 3611 llvm/include/llvm/Support/MathExtras.h 170422 47 3626 llvm/include/llvm/Support/Compiler.h 162225 45 3605 llvm/include/llvm/ADT/Optional.h 158319 63 2513 llvm/include/llvm/ADT/Triple.h 140322 39 3598 llvm/include/llvm/ADT/StringRef.h 137647 59 2333 llvm/include/llvm/Support/Error.h 131619 73 1803 llvm/include/llvm/Support/FileSystem.h Before this change, touching InitializePasses.h would cause 1345 files to recompile. After this change, touching it only causes 550 compiles in an incremental rebuild. Reviewers: bkramer, asbirlea, bollu, jdoerfert Differential Revision: https://reviews.llvm.org/D70211
2019-10-30[X86] Make memcmp vector lowering handle arbitrary expansionsDavid Zarzycki1-2/+2
Teach combineVectorSizedSetCCEquality() to handle arbitrary memcmp expansions but do not change any default policy for now. This also fixes a bug in the memcmp expansion itself when large displacements are needed. https://reviews.llvm.org/D69507
2019-09-10Revert "Reland "r364412 [ExpandMemCmp][MergeICmps] Move passes out of ↵Dmitri Gribenko1-0/+871
CodeGen into opt pipeline."" This reverts commit r371502, it broke tests (clang/test/CodeGenCXX/auto-var-init.cpp). llvm-svn: 371507
2019-09-10Reland "r364412 [ExpandMemCmp][MergeICmps] Move passes out of CodeGen into ↵Clement Courbet1-871/+0
opt pipeline." With a fix for sanitizer breakage (see explanation in D60318). llvm-svn: 371502
2019-09-07Change TargetLibraryInfo analysis passes to always require FunctionTeresa Johnson1-1/+1
Summary: This is the first change to enable the TLI to be built per-function so that -fno-builtin* handling can be migrated to use function attributes. See discussion on D61634 for background. This is an enabler for fixing handling of these options for LTO, for example. This change should not affect behavior, as the provided function is not yet used to build a specifically per-function TLI, but rather enables that migration. Most of the changes were very mechanical, e.g. passing a Function to the legacy analysis pass's getTLI interface, or in Module level cases, adding a callback. This is similar to the way the per-function TTI analysis works. There was one place where we were looking for builtins but not in the context of a specific function. See FindCXAAtExit in lib/Transforms/IPO/GlobalOpt.cpp. I'm somewhat concerned my workaround could provide the wrong behavior in some corner cases. Suggestions welcome. Reviewers: chandlerc, hfinkel Subscribers: arsenm, dschuff, jvesely, nhaehnle, mehdi_amini, javed.absar, sbc100, jgravelle-google, eraman, aheejin, steven_wu, george.burgess.iv, dexonsmith, jfb, asbirlea, gchatelet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66428 llvm-svn: 371284
2019-06-26Revert "r364412 [ExpandMemCmp][MergeICmps] Move passes out of CodeGen into ↵Clement Courbet1-0/+871
opt pipeline." Breaks sanitizers: libFuzzer :: cxxstring.test libFuzzer :: memcmp.test libFuzzer :: recommended-dictionary.test libFuzzer :: strcmp.test libFuzzer :: value-profile-mem.test libFuzzer :: value-profile-strcmp.test llvm-svn: 364416
2019-06-26[ExpandMemCmp][MergeICmps] Move passes out of CodeGen into opt pipeline.Clement Courbet1-871/+0
This allows later passes (in particular InstCombine) to optimize more cases. One that's important to us is `memcmp(p, q, constant) < 0` and memcmp(p, q, constant) > 0. llvm-svn: 364412
2019-06-25[ExpandMemCmp] Move all options to TargetTransformInfo.Clement Courbet1-29/+20
Split off from D60318. llvm-svn: 364281
2019-05-18MemCmpExpansion::getCompareLoadPairs - assert we find a comparison diff. NFCI.Simon Pilgrim1-1/+3
Fix scan-build uninitialized warning and assert the final diff isn't null. llvm-svn: 361095
2019-04-12Add options for MaxLoadsPerMemcmp(OptSize).Hiroshi Yamauchi1-2/+15
Reviewers: davidxl Reviewed By: davidxl Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60587 llvm-svn: 358287