summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TypePromotion.cpp
AgeCommit message (Collapse)Author
2025-04-05[TypePromotion] Do not zero-extend getelementptr indexes since signedAntonio Frighetto
A miscompilation issue has been addressed with improved handling. Fixes: https://github.com/llvm/llvm-project/issues/133928. Alive2: https://alive2.llvm.org/ce/z/gcMNvS.
2025-01-24[NFC][DebugInfo] Use iterator moveBefore at many call-sites (#123583)Jeremy Morse
As part of the "RemoveDIs" project, BasicBlock::iterator now carries a debug-info bit that's needed when getFirstNonPHI and similar feed into instruction insertion positions. Call-sites where that's necessary were updated a year ago; but to ensure some type safety however, we'd like to have all calls to moveBefore use iterators. This patch adds a (guaranteed dereferenceable) iterator-taking moveBefore, and changes a bunch of call-sites where it's obviously safe to change to use it by just calling getIterator() on an instruction pointer. A follow-up patch will contain less-obviously-safe changes. We'll eventually deprecate and remove the instruction-pointer insertBefore, but not before adding concise documentation of what considerations are needed (very few).
2024-08-16[CodeGen] Use range-based for loops (NFC) (#104536)Kazu Hirata
2024-08-13[TypePromotion] Use return value from SmallPtrSet::insert to avoid a call to ↵Craig Topper
SmallPtrSet::count. NFC (#103008)
2024-06-29[IRBuilder] Don't include Module.h (NFC) (#97159)Nikita Popov
This used to be necessary to fetch the DataLayout, but isn't anymore.
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov
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-03-28[RISCV][TypePromotion] Dont generate truncs if PromotedType is greater than ↵Sudharsan Veeravalli
Source Type (#86941) We currently check if the source and promoted types are not equal before generating truncate instructions. This does not work for RV64 where the promoted type is i64 and this lead to a crash due to the generation of truncate instructions from i32 to i64. Fixes #86400
2024-03-11Recommit "[TypePromotion] Support positive addition amounts in isSafeWrap. ↵Craig Topper
(#81690)" With special case with Add constant is 0. Original message: We can support these by changing the sext promotion to -zext(-C) and replacing a sgt check with ugt. Reframing the logic in terms of how the unsigned range are affected. More comments in the patch. The new cases check isLegalAddImmediate to avoid some regressions in lit tests.
2024-03-11Revert "[TypePromotion] Support positive addition amounts in isSafeWrap. ↵Craig Topper
(#81690)" This reverts commit 0813b90ff5d195d8a40c280f6b745f1cc43e087a. Fixes miscompile reported in #84718.
2024-03-01[TypePromotion] Support positive addition amounts in isSafeWrap. (#81690)Craig Topper
We can support these by changing the sext promotion to -zext(-C) and replacing a sgt check with ugt. Reframing the logic in terms of how the unsigned range are affected. More comments in the patch. The new cases check isLegalAddImmediate to avoid some regressions in lit tests.
2024-02-13[TypePromotion] Remove an unreachable 'return false'. NFCCraig Topper
The if and the else above this both return so this is unreachable. Delete it and remove the else after return.
2024-02-13[RISCV] Enable the TypePromotion pass from AArch64/ARM.Craig Topper
This pass looks for unsigned icmps that have illegal types and tries to widen the use/def graph to improve the placement of the zero extends that type legalization would need to insert. I've explicitly disabled it for i32 by adding a check for isSExtCheaperThanZExt to the pass. The generated code isn't perfect, but my data shows a net dynamic instruction count improvement on spec2017 for both base and Zba+Zbb+Zbs.
2023-10-11Clean up strange uses of getAnalysisIfAvailable (#65729)Jay Foad
After a pass calls addRequired<X>() it is strange to call getAnalysisIfAvailable<X>() because analysis X should always be available. Use getAnalysis<X>() instead.
2023-09-28[TypePromotion] Avoid use of ConstantExpr::getZExt() (NFC)Nikita Popov
Instead work on APInt.
2023-06-09[TypePromotion] Don't treat bitcast as a SourceDavid Green
This removes BitCasts from isSource in Type Promotion, as I don't believe they need to be treated as Sources. They will usually be from floats or hoisted constants, where constants will be handled already. This fixes #62513, but didn't otherwise cause any differences in the tests I ran. Differential Revision: https://reviews.llvm.org/D152112
2023-06-07Revert "[TypePromotion] Don't treat bitcast as a Source"Paul Kirth
This reverts commit 27aea17fe061f9778bb1e8ff5fdf9fc0fb03abe1. For details, see: https://reviews.llvm.org/D152112 Fuchsia CI failure: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-arm64/b8779118297575483793/overview
2023-06-05[TypePromotion] Don't treat bitcast as a SourceDavid Green
This removes BitCasts from isSource in Type Promotion, as I don't believe they need to be treated as Sources. They will usually be from floats or hoisted constants, where constants will be handled already. This fixes #62513, but didn't otherwise cause any differences in the tests I ran. Differential Revision: https://reviews.llvm.org/D152112
2023-03-02[TypePromotion] Deference pointer before printing it in a debug message.Craig Topper
Without deferencing it just prints the value of the pointer which isn't meaningful. Dereferencing prints the operand.
2023-01-11[NFC] Use TypeSize::geFixedValue() instead of TypeSize::getFixedSize()Guillaume Chatelet
This change is one of a series to implement the discussion from https://reviews.llvm.org/D141134.
2023-01-03[TypePromotion] NewPM support.Samuel Parker
Differential Revision: https://reviews.llvm.org/D140893
2023-01-03[TypePromotion] Add truncate in ConvertTruncs when the original truncate ↵chenglin.bi
type is not extend type If the src type is not extend type, after convert the truncate to and we need to truncate the and also to make sure the all user is legal. The old fix D137613 doesn't work when the truncate convert to and have the other users. So this time I try to add the truncate after and to avoid all these potential issues. Fix: #59554 Reviewed By: samparker Differential Revision: https://reviews.llvm.org/D140869
2022-11-09[TypePromotion] Replace Zext to Truncate for the case src bitwidth is largerchenglin.bi
Fix: https://github.com/llvm/llvm-project/issues/58843 Reviewed By: samtebbs Differential Revision: https://reviews.llvm.org/D137613
2022-09-13[TypePromotionPass] Don't treat phi's as ToPromoteDavid Green
This attempts to stop the type promotion pass transforming where it is not profitable, by not marking PhiNodes as ToPromote and being more aggressive about pulling extends out of loops. Differential Revision: https://reviews.llvm.org/D133203
2022-09-02[TypePromotionPass] Rename variable to avoid name conflict. NFCDavid Green
2022-08-17[TypePromotion] Don't promote PHI + ZExt if wider than RegisterBitWidthAndre Vieira
Differential Revision: https://reviews.llvm.org/D131966
2022-08-16[TypePromotion] Only search for PHI + ZExt promotion of IntegersAndre Vieira
Differential Revision: https://reviews.llvm.org/D131948
2022-08-11[TypePromotion] Search from ZExt + PHIAndre Vieira
Expand TypePromotion pass to try to promote PHI-nodes in loops that are the operand of a ZExt, using the ZExt's result type to determine the Promote Width. Differential Revision: https://reviews.llvm.org/D111237
2022-08-11[TypePromotion] Hoist out Promote Width calculationAndre Vieira
Hoist out promote width calculation to simplify runOnFunction. Differential Revision: https://reviews.llvm.org/D131489
2022-08-11[TypePromotion] Don't delete Insns when iteratingAndre Vieira
Differential Revision: https://reviews.llvm.org/D131488
2022-08-11[TypePromotion] Don't insert Truncate for a no-op ZExtAndre Vieira
Differential Revision: https://reviews.llvm.org/D131487
2022-07-17[CodeGen] Qualify auto variables in for loops (NFC)Kazu Hirata
2022-05-26[iwyu] Handle regressions in libLLVM header includeserge-sans-paille
Running iwyu-diff on LLVM codebase since 7030654296a0416bd9402a0278 detected a few regressions, fixing them. Differential Revision: https://reviews.llvm.org/D126417
2022-05-24[TypePromotion] Avoid unnecessary trunc zext pairsSam Parker
Any zext 'sink' should already have an operand that is in the legal value, so avoid using a trunc and just use the trunc operand instead. Differential Revision: https://reviews.llvm.org/D118905
2022-05-21[TypePromotion] Refine fix sext/zext for promoted constant from D125294.Craig Topper
Reviewing the code again, I believe the sext is needed on the LHS or RHS for ICmp and only on the RHS for Add. Add an opcode check before checking the operand number. Fixes PR55627. Differential Revision: https://reviews.llvm.org/D125654
2022-05-20[TypePromotion] Fix another case for sext vs zext in promoted constant.Craig Topper
If the SafeWrap operation is a subtract, we negated the constant to treat the subtract as an addition. The sext was based on the operation being addition. So we really need to do (neg (sext (neg C))) when promoting the constant. This is equivalent to (sext C) for every value of C except the min signed value. For min signed value we need to do (zext C) instead. Fixes PR55490. Differential Revision: https://reviews.llvm.org/D125653
2022-05-13[TypePromotion] Avoid some unnecessary truncsSam Parker
Recommit. Check for legal zext 'sinks' before inserting a trunc. Differential Revision: https://reviews.llvm.org/D115451
2022-05-12[TypePromotion] Promote undef by converting to 0.Craig Topper
If we're promoting an undef I think that means that we expect the upper bits are zero. undef doesn't guarantee that. This patch replaces undef with 0 to ensure this. This matches how a zext or sext of undef would be folded by InstCombine/InstSimplify. I haven't found a failure from this was just thinking through the code. Differential Revision: https://reviews.llvm.org/D123174
2022-05-11[TypePromotion] Fix sext vs zext in promoted constantDavid Green
As pointed out in #55342, given non-canonical IR with multiple constants, we check the second operand in isSafeWrap, but can promote both with sext. Fix that as suggested by @craig.topper by ensuring we only extend the second constant if multiple are present. Fixes #55342 Differential Revision: https://reviews.llvm.org/D125294
2022-05-11[TypePromotion] Format Type Promotion. NFCDavid Green
This clang-formats the TypePromotion code, with the only meaningful change being the removal of a verifyFunction call inside a LLVM_DEBUG, and the printing of the entire function which can be better handled via -print-after-all.
2022-03-16Cleanup codegen includesserge-sans-paille
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 Weber
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-paille
after: 1061034926 before: 1063332844 Differential Revision: https://reviews.llvm.org/D121169
2022-03-01Revert "[TypePromotion] Avoid some unnecessary truncs"Sam Parker
This reverts commit 281d29b8fed369c6ebe33ed85c518fc1ed81f44a. Report of a miscompilation and awaiting a reproducer.
2022-02-02[TypePromotion] Avoid some unnecessary truncsSam Parker
Check for legal zext 'sinks' before inserting a trunc. Differential Revision: https://reviews.llvm.org/D115451
2022-01-02Remove redundant void arguments (NFC)Kazu Hirata
Identified by modernize-redundant-void-arg.
2021-11-14[TypePromotion] Extend TypePromotion::isSafeWrapDavid Green
This modifies the preconditions of TypePromotion's isSafeWrap method, to allow it to work from all constants from the ICmp. Using the code: %a = add %x, C1 %c = icmp ult %a, C2 According to Alive, we can prove that is equivalent to icmp ult (add zext(%x), sext(C1)), zext(C2) given C1 <=s 0 and C1 >s C2. https://alive2.llvm.org/ce/z/CECYZB Which is similar to what is already present. We can also prove icmp ult (add zext(%x), sext(C1)), sext(C2) given C1 <=s 0 and C1 <=s C2. https://alive2.llvm.org/ce/z/KKgyeL The PrepareWrappingAdds method was removed, and the constants are now altered to sext or zext directly as required by the above methods. Differential Revision: https://reviews.llvm.org/D113678
2021-11-10[TypePromotion] Fix a hardcoded use of 32 as the size being promoted to.Craig Topper
At least I think that's what the 32 here is. Use RegisterBitWidth instead. While there replace zext with zextOrSelf to simplify the code. Reviewed By: samparker, dmgreen Differential Revision: https://reviews.llvm.org/D113495
2021-10-03[Analysis, CodeGen] Migrate from arg_operands to args (NFC)Kazu Hirata
Note that arg_operands is considered a legacy name. See llvm/include/llvm/IR/InstrTypes.h for details.
2021-09-22Mark CFG as preserved in TypePromotion and InterleaveAccess passesDavid Green
Neither of these passes modify the CFG, allowing us to preserve DomTree and LoopInfo across them by using setPreservesCFG. Differential Revision: https://reviews.llvm.org/D110161
2021-09-09[APInt] Normalize naming on keep constructors / predicate methods.Chris Lattner
This renames the primary methods for creating a zero value to `getZero` instead of `getNullValue` and renames predicates like `isAllOnesValue` to simply `isAllOnes`. This achieves two things: 1) This starts standardizing predicates across the LLVM codebase, following (in this case) ConstantInt. The word "Value" doesn't convey anything of merit, and is missing in some of the other things. 2) Calling an integer "null" doesn't make any sense. The original sin here is mine and I've regretted it for years. This moves us to calling it "zero" instead, which is correct! APInt is widely used and I don't think anyone is keen to take massive source breakage on anything so core, at least not all in one go. As such, this doesn't actually delete any entrypoints, it "soft deprecates" them with a comment. Included in this patch are changes to a bunch of the codebase, but there are more. We should normalize SelectionDAG and other APIs as well, which would make the API change more mechanical. Differential Revision: https://reviews.llvm.org/D109483