[clang] 7cac7e0 - [IR] Prefer hasFnAttribute() where possible (NFC)
Author: Nikita Popov Date: 2020-06-15T09:30:35+02:00 New Revision: 7cac7e0cfc72c865bfe42cc5c068e17218e600d5 URL: https://github.com/llvm/llvm-project/commit/7cac7e0cfc72c865bfe42cc5c068e17218e600d5 DIFF: https://github.com/llvm/llvm-project/commit/7cac7e0cfc72c865bfe42cc5c068e17218e600d5.diff LOG: [IR] Prefer hasFnAttribute() where possible (NFC) When checking for an enum function attribute, use hasFnAttribute() rather than hasAttribute() at FunctionIndex, because it is significantly faster (and more concise to boot). Added: Modified: clang/lib/CodeGen/CGCall.cpp llvm/include/llvm/IR/InstrTypes.h llvm/lib/IR/Instructions.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.cpp llvm/lib/Target/X86/X86ISelLowering.cpp llvm/lib/Target/X86/X86IndirectBranchTracking.cpp Removed: diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 136782fccf40..17282e2bafe6 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4861,8 +4861,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, CannotThrow = true; } else { // Otherwise, nounwind call sites will never throw. -CannotThrow = Attrs.hasAttribute(llvm::AttributeList::FunctionIndex, - llvm::Attribute::NoUnwind); +CannotThrow = Attrs.hasFnAttribute(llvm::Attribute::NoUnwind); } // If we made a temporary, be sure to clean up after ourselves. Note that we diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h index 8ad39add81d5..d0af5ccc5240 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -2128,7 +2128,7 @@ class CallBase : public Instruction { bool hasFnAttrOnCalledFunction(StringRef Kind) const; template bool hasFnAttrImpl(AttrKind Kind) const { -if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind)) +if (Attrs.hasFnAttribute(Kind)) return true; // Operand bundles override attributes on the called function, but don't diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 22de967f1b5e..0068ec5f7808 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -330,13 +330,13 @@ bool CallBase::paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const { bool CallBase::hasFnAttrOnCalledFunction(Attribute::AttrKind Kind) const { if (const Function *F = getCalledFunction()) -return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, Kind); +return F->getAttributes().hasFnAttribute(Kind); return false; } bool CallBase::hasFnAttrOnCalledFunction(StringRef Kind) const { if (const Function *F = getCalledFunction()) -return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, Kind); +return F->getAttributes().hasFnAttribute(Kind); return false; } diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 88c4116b15ef..f1dc4b725ea1 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2957,15 +2957,14 @@ void Verifier::visitCallBase(CallBase &Call) { Function *Callee = dyn_cast(Call.getCalledOperand()->stripPointerCasts()); - if (Attrs.hasAttribute(AttributeList::FunctionIndex, Attribute::Speculatable)) { + if (Attrs.hasFnAttribute(Attribute::Speculatable)) { // Don't allow speculatable on call sites, unless the underlying function // declaration is also speculatable. Assert(Callee && Callee->isSpeculatable(), "speculatable attribute may not apply to call sites", Call); } - if (Attrs.hasAttribute(AttributeList::FunctionIndex, - Attribute::Preallocated)) { + if (Attrs.hasFnAttribute(Attribute::Preallocated)) { Assert(Call.getCalledFunction()->getIntrinsicID() == Intrinsic::call_preallocated_arg, "preallocated as a call site attribute can only be on " diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index acfd77d5fd8c..6177a80d0aae 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -14537,8 +14537,7 @@ bool AArch64TargetLowering::isIntDivCheap(EVT VT, AttributeList Attr) const { // integer division, leaving the division as-is is a loss even in terms of // size, because it will have to be scalarized, while the alternative code // sequence can be performed in vector form. - bool OptSize = - Attr.hasAttribute(AttributeList::FunctionIndex, Attribute::MinSize); + bool OptSize = Attr.hasFnAttribute(Attribute::MinSize); return OptSize && !VT.isVector(); } diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index a0d9d218982a..0245420af689 100644 --- a/llvm/lib/Targ
[clang] afc287e - Fix clang test after D76886
Author: Nikita Popov Date: 2020-04-30T23:42:38+02:00 New Revision: afc287e0abec710398465ee1f86237513f2b5091 URL: https://github.com/llvm/llvm-project/commit/afc287e0abec710398465ee1f86237513f2b5091 DIFF: https://github.com/llvm/llvm-project/commit/afc287e0abec710398465ee1f86237513f2b5091.diff LOG: Fix clang test after D76886 Added: Modified: clang/test/CodeGen/builtin-movdir.c Removed: diff --git a/clang/test/CodeGen/builtin-movdir.c b/clang/test/CodeGen/builtin-movdir.c index 8d4edfbf8f77..e13cc776edd6 100644 --- a/clang/test/CodeGen/builtin-movdir.c +++ b/clang/test/CodeGen/builtin-movdir.c @@ -24,11 +24,6 @@ void test_directstore64(void *dst, uint64_t value) { void test_dir64b(void *dst, const void *src) { // CHECK-LABEL: test_dir64b - // CHECK: [[PTRINT1:%.+]] = ptrtoint - // X86: [[MASKEDPTR1:%.+]] = and i32 [[PTRINT1]], 63 - // X86: [[MASKCOND1:%.+]] = icmp eq i32 [[MASKEDPTR1]], 0 - // X86_64: [[MASKEDPTR1:%.+]] = and i64 [[PTRINT1]], 63 - // X86_64: [[MASKCOND1:%.+]] = icmp eq i64 [[MASKEDPTR1]], 0 // CHECK: call void @llvm.x86.movdir64b _movdir64b(dst, src); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 25af353 - [NewPM][LVI] Abandon LVI after CVP
Author: Nikita Popov Date: 2020-08-01T23:47:46+02:00 New Revision: 25af353b0e74907d5d50c8616b885bd1f73a68b3 URL: https://github.com/llvm/llvm-project/commit/25af353b0e74907d5d50c8616b885bd1f73a68b3 DIFF: https://github.com/llvm/llvm-project/commit/25af353b0e74907d5d50c8616b885bd1f73a68b3.diff LOG: [NewPM][LVI] Abandon LVI after CVP As mentioned on D70376, LVI can currently cause performance issues when running under NewPM. The problem is that, unlike the legacy pass manager, NewPM will not immediately discard the LVI analysis if the following pass does not need it. This is a problem, because LVI has a high memory requirement, and mass invalidation of LVI values is very inefficient. LVI should only be alive during passes that actively interact with it. This patch addresses the issue by explicitly abandoning LVI after CVP, which gets us back to the LegacyPM behavior. Differential Revision: https://reviews.llvm.org/D84959 Added: Modified: clang/test/CodeGen/thinlto-distributed-newpm.ll llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp llvm/test/Other/new-pm-defaults.ll llvm/test/Other/new-pm-thinlto-defaults.ll llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll Removed: diff --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll b/clang/test/CodeGen/thinlto-distributed-newpm.ll index caf294df8eb8..9f9a8bec4ef5 100644 --- a/clang/test/CodeGen/thinlto-distributed-newpm.ll +++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll @@ -97,6 +97,7 @@ ; CHECK-O: Running pass: JumpThreadingPass on main ; CHECK-O: Running analysis: LazyValueAnalysis on main ; CHECK-O: Running pass: CorrelatedValuePropagationPass on main +; CHECK-O: Invalidating analysis: LazyValueAnalysis on main ; CHECK-O: Running pass: SimplifyCFGPass on main ; CHECK-O3: Running pass: AggressiveInstCombinePass on main ; CHECK-O: Running pass: InstCombinePass on main @@ -144,7 +145,6 @@ ; CHECK-O: Invalidating analysis: BasicAA on main ; CHECK-O: Invalidating analysis: AAManager on main ; CHECK-O: Invalidating analysis: MemorySSAAnalysis on main -; CHECK-O: Invalidating analysis: LazyValueAnalysis on main ; CHECK-O: Invalidating analysis: LoopAnalysis on main ; CHECK-O: Invalidating analysis: PhiValuesAnalysis on main ; CHECK-O: Invalidating analysis: MemoryDependenceAnalysis on main diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 48968166c605..397d62a5d21d 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -973,11 +973,19 @@ CorrelatedValuePropagationPass::run(Function &F, FunctionAnalysisManager &AM) { bool Changed = runImpl(F, LVI, DT, getBestSimplifyQuery(AM, F)); - if (!Changed) -return PreservedAnalyses::all(); PreservedAnalyses PA; - PA.preserve(); - PA.preserve(); - PA.preserve(); + if (!Changed) { +PA = PreservedAnalyses::all(); + } else { +PA.preserve(); +PA.preserve(); +PA.preserve(); + } + + // Keeping LVI alive is expensive, both because it uses a lot of memory, and + // because invalidating values in LVI is expensive. While CVP does preserve + // LVI, we know that passes after JumpThreading+CVP will not need the result + // of this analysis, so we forcefully discard it early. + PA.abandon(); return PA; } diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll index 8f75e3ce0bf3..59c24acb17f0 100644 --- a/llvm/test/Other/new-pm-defaults.ll +++ b/llvm/test/Other/new-pm-defaults.ll @@ -147,6 +147,7 @@ ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass +; CHECK-O23SZ-NEXT: Invalidating analysis: LazyValueAnalysis ; CHECK-O-NEXT: Running pass: SimplifyCFGPass ; CHECK-O3-NEXT: AggressiveInstCombinePass ; CHECK-O-NEXT: Running pass: InstCombinePass @@ -200,7 +201,9 @@ ; CHECK-O-NEXT: Running pass: InstCombinePass ; CHECK-EP-PEEPHOLE-NEXT: Running pass: NoOpFunctionPass ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass +; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass +; CHECK-O23SZ-NEXT: Invalidating analysis: LazyValueAnalysis ; CHECK-O23SZ-NEXT: Running pass: DSEPass ; CHECK-O23SZ-NEXT: Starting llvm::Function pass manager run. ; CHECK-O23SZ-NEXT: Running pass: LoopSimplifyPass diff --git a/llvm/test/Other/new-pm-thinlto-defaults.ll b/llvm/test/Other/new-pm-thinlto-defaults.ll index a39656cd26f6..0b9b52a57e2a 100644 --- a/llvm/test/Other/new-pm-t
[clang] f89f7da - [IR] Convert null-pointer-is-valid into an enum attribute
Author: Nikita Popov Date: 2020-05-15T19:41:07+02:00 New Revision: f89f7da999f362e4213c69923328dd1033276e59 URL: https://github.com/llvm/llvm-project/commit/f89f7da999f362e4213c69923328dd1033276e59 DIFF: https://github.com/llvm/llvm-project/commit/f89f7da999f362e4213c69923328dd1033276e59.diff LOG: [IR] Convert null-pointer-is-valid into an enum attribute The "null-pointer-is-valid" attribute needs to be checked by many pointer-related combines. To make the check more efficient, convert it from a string into an enum attribute. In the future, this attribute may be replaced with data layout properties. Differential Revision: https://reviews.llvm.org/D78862 Added: Modified: clang/lib/CodeGen/CGCall.cpp clang/test/CodeGen/delete-null-pointer-checks.c llvm/docs/LangRef.rst llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/Attributes.td llvm/include/llvm/IR/AutoUpgrade.h llvm/lib/AsmParser/LLLexer.cpp llvm/lib/AsmParser/LLParser.cpp llvm/lib/AsmParser/LLToken.h llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/IR/Attributes.cpp llvm/lib/IR/AutoUpgrade.cpp llvm/lib/IR/Function.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp llvm/test/Analysis/MemorySSA/cyclicphi.ll llvm/test/Analysis/ValueTracking/assume.ll llvm/test/Bitcode/attributes.ll llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll llvm/test/Transforms/Attributor/align.ll llvm/test/Transforms/Attributor/nocapture-1.ll llvm/test/Transforms/Attributor/nonnull.ll llvm/test/Transforms/Attributor/norecurse.ll llvm/test/Transforms/Attributor/undefined_behavior.ll llvm/test/Transforms/CorrelatedValuePropagation/non-null.ll llvm/test/Transforms/FunctionAttrs/nocapture.ll llvm/test/Transforms/FunctionAttrs/nonnull.ll llvm/test/Transforms/GVN/PRE/2018-06-08-pre-load-dbgloc-no-null-opt.ll llvm/test/Transforms/GlobalOpt/MallocSROA-section-no-null-opt.ll llvm/test/Transforms/GlobalOpt/heap-sra-1-no-null-opt.ll llvm/test/Transforms/GlobalOpt/heap-sra-1.ll llvm/test/Transforms/GlobalOpt/heap-sra-2-no-null-opt.ll llvm/test/Transforms/GlobalOpt/heap-sra-2.ll llvm/test/Transforms/GlobalOpt/heap-sra-3-no-null-opt.ll llvm/test/Transforms/GlobalOpt/heap-sra-3.ll llvm/test/Transforms/GlobalOpt/heap-sra-4-no-null-opt.ll llvm/test/Transforms/GlobalOpt/heap-sra-4.ll llvm/test/Transforms/GlobalOpt/heap-sra-phi-no-null-opt.ll llvm/test/Transforms/GlobalOpt/heap-sra-phi.ll llvm/test/Transforms/GlobalOpt/load-store-global-no-null-opt.ll llvm/test/Transforms/GlobalOpt/malloc-promote-1-no-null-opt.ll llvm/test/Transforms/GlobalOpt/malloc-promote-1.ll llvm/test/Transforms/GlobalOpt/malloc-promote-2-no-null-opt.ll llvm/test/Transforms/GlobalOpt/malloc-promote-2.ll llvm/test/Transforms/GlobalOpt/storepointer-compare-no-null-opt.ll llvm/test/Transforms/GlobalOpt/storepointer-no-null-opt.ll llvm/test/Transforms/IPConstantProp/PR26044.ll llvm/test/Transforms/Inline/attributes.ll llvm/test/Transforms/InstCombine/atomic.ll llvm/test/Transforms/InstCombine/invariant.group.ll llvm/test/Transforms/InstCombine/invoke.ll llvm/test/Transforms/InstCombine/lifetime-no-null-opt.ll llvm/test/Transforms/InstCombine/load.ll llvm/test/Transforms/InstCombine/mem-deref-bytes.ll llvm/test/Transforms/InstCombine/memchr.ll llvm/test/Transforms/InstCombine/memcpy-addrspace.ll llvm/test/Transforms/InstCombine/memcpy-from-global.ll llvm/test/Transforms/InstCombine/memrchr.ll llvm/test/Transforms/InstCombine/select.ll llvm/test/Transforms/InstCombine/store.ll llvm/test/Transforms/InstCombine/strchr-1.ll llvm/test/Transforms/InstCombine/strcpy_chk-64.ll llvm/test/Transforms/InstCombine/strlen-1.ll llvm/test/Transforms/InstCombine/strncat-2.ll llvm/test/Transforms/InstCombine/strncmp-1.ll llvm/test/Transforms/InstCombine/strrchr-1.ll llvm/test/Transforms/InstCombine/strstr-1.ll llvm/test/Transforms/InstCombine/wcslen-1.ll llvm/test/Transforms/InstSimplify/compare.ll llvm/test/Transforms/LoopIdiom/pr28196.ll llvm/test/Transforms/LoopVersioning/lcssa.ll llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll llvm/test/Transforms/SimplifyCFG/invoke.ll llvm/test/Transforms/SimplifyCFG/phi-undef-loadstore.ll llvm/test/Transforms/SimplifyCFG/trap-no-null-opt-debugloc.ll llvm/test/Transforms/SimplifyCFG/trapping-load-unreachable.ll llvm/test/Transforms/Util/assume-builder.ll mlir/test/Target/llvmir.mlir Removed: diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 32a9ba499ecb..068d053d17cc 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1744,7 +1744,7 @@ void CodeG
[clang] c04eab8 - [Flang] Use find_program() to find clang-tblgen
Author: Nikita Popov Date: 2022-08-29T11:09:25+02:00 New Revision: c04eab8c78e517210c7641551ec008b09bfe20d0 URL: https://github.com/llvm/llvm-project/commit/c04eab8c78e517210c7641551ec008b09bfe20d0 DIFF: https://github.com/llvm/llvm-project/commit/c04eab8c78e517210c7641551ec008b09bfe20d0.diff LOG: [Flang] Use find_program() to find clang-tblgen There are two scenarios here: 1. Standalone flang build, where we use an installed clang-tblgen binary. We need to use find_package() to find it. 2. Combined build of clang and flang, where we want to use the path specified in CLANG_TABLEGEN_EXE during the clang build -- however, this variable was previously not exported. The new implementation matches what is done for mlir-tblgen. Differential Revision: https://reviews.llvm.org/D131475 Added: Modified: clang/CMakeLists.txt flang/docs/CMakeLists.txt Removed: diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 2b1e968da3960..1064cfd0a35a3 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -484,6 +484,9 @@ option(CLANG_INCLUDE_TESTS add_subdirectory(utils/TableGen) +# Export CLANG_TABLEGEN_EXE for use by flang docs. +set(CLANG_TABLEGEN_EXE "${CLANG_TABLEGEN_EXE}" CACHE INTERNAL "") + add_subdirectory(include) # All targets below may depend on all tablegen'd files. diff --git a/flang/docs/CMakeLists.txt b/flang/docs/CMakeLists.txt index 770343cd29b80..3414b8e3acc46 100644 --- a/flang/docs/CMakeLists.txt +++ b/flang/docs/CMakeLists.txt @@ -126,7 +126,7 @@ if (LLVM_ENABLE_SPHINX) ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py) # CLANG_TABLEGEN_EXE variable needs to be set for clang_tablegen to run without error - set(CLANG_TABLEGEN_EXE clang-tblgen) + find_program(CLANG_TABLEGEN_EXE "clang-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs FlangOptionsDocs.td docs-flang-html) endif() if (${SPHINX_OUTPUT_MAN}) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] a11e2d7 - [libclc] Quote addition of CLC/LLAsm flags
Author: Nikita Popov Date: 2022-08-31T11:10:24+02:00 New Revision: a11e2d7366a11385e23d142ac93065a861b70a16 URL: https://github.com/llvm/llvm-project/commit/a11e2d7366a11385e23d142ac93065a861b70a16 DIFF: https://github.com/llvm/llvm-project/commit/a11e2d7366a11385e23d142ac93065a861b70a16.diff LOG: [libclc] Quote addition of CLC/LLAsm flags Otherwise cmake will insert a semicolon if flags are already set. Differential Revision: https://reviews.llvm.org/D131490 Added: Modified: libclc/CMakeLists.txt Removed: diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 9773b2cc925ff..96519e09e28e4 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -136,8 +136,8 @@ set( LLVM_VERSION_DEFINE "-DHAVE_LLVM=0x${LLVM_MAJOR}0${LLVM_MINOR}" ) # LLVM 13 enables standard includes by default if( ${LLVM_VERSION} VERSION_GREATER "12.99.99" ) - set( CMAKE_LLAsm_FLAGS ${CMAKE_LLAsm_FLAGS} -cl-no-stdinc ) - set( CMAKE_CLC_FLAGS ${CMAKE_CLC_FLAGS} -cl-no-stdinc ) + set( CMAKE_LLAsm_FLAGS "${CMAKE_LLAsm_FLAGS} -cl-no-stdinc") + set( CMAKE_CLC_FLAGS "${CMAKE_CLC_FLAGS} -cl-no-stdinc") endif() enable_language( CLC LLAsm ) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7179779 - [OpenMP] Mark -fopenmp-implicit-rpath as NoArgumentUnused
Author: Nikita Popov Date: 2022-09-06T09:44:45+02:00 New Revision: 71797797f7a759245cb39b93307e0641c511170c URL: https://github.com/llvm/llvm-project/commit/71797797f7a759245cb39b93307e0641c511170c DIFF: https://github.com/llvm/llvm-project/commit/71797797f7a759245cb39b93307e0641c511170c.diff LOG: [OpenMP] Mark -fopenmp-implicit-rpath as NoArgumentUnused This matches the behavior for all the other -fopenmp options, as well as -frtlib-add-rpath. For context, Fedora passes this flag by default in case OpenMP is used, and this results in a warning if it (usually) isn't, which causes build failures for some programs with unnecessarily strict build systems (like Ruby). Differential Revision: https://reviews.llvm.org/D133316 Added: Modified: clang/include/clang/Driver/Options.td Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c7c34f072ba23..58a316b0180e6 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4114,7 +4114,8 @@ defm openmp_implicit_rpath: BoolFOption<"openmp-implicit-rpath", LangOpts<"OpenMP">, DefaultTrue, PosFlag, - NegFlag>; + NegFlag, + BothFlags<[NoArgumentUnused]>>; def r : Flag<["-"], "r">, Flags<[LinkerInput,NoArgumentUnused]>, Group; def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[CC1Option, FlangOption, NoXarchOption]>, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 98a3a34 - [ConstantExpr] Don't create fneg expressions
Author: Nikita Popov Date: 2022-09-07T11:27:25+02:00 New Revision: 98a3a340c3612c06c51d7bb36bfc5857ab06a951 URL: https://github.com/llvm/llvm-project/commit/98a3a340c3612c06c51d7bb36bfc5857ab06a951 DIFF: https://github.com/llvm/llvm-project/commit/98a3a340c3612c06c51d7bb36bfc5857ab06a951.diff LOG: [ConstantExpr] Don't create fneg expressions Don't create fneg expressions unless explicitly requested by IR or bitcode. Added: Modified: clang/test/CodeGen/constantexpr-fneg.c llvm/include/llvm/Analysis/TargetFolder.h llvm/include/llvm/IR/ConstantFolder.h llvm/lib/Analysis/ConstantFolding.cpp llvm/test/Transforms/InstCombine/fmul.ll llvm/test/Transforms/InstCombine/fneg.ll llvm/test/Transforms/Reassociate/crash2.ll Removed: diff --git a/clang/test/CodeGen/constantexpr-fneg.c b/clang/test/CodeGen/constantexpr-fneg.c index 17873345daee7..7fc78cfebf8f3 100644 --- a/clang/test/CodeGen/constantexpr-fneg.c +++ b/clang/test/CodeGen/constantexpr-fneg.c @@ -2,8 +2,7 @@ // RUN: llvm-dis %t.bc -o - | FileCheck %s // Test case for PR45426. Make sure we do not crash while writing bitcode -// containing a simplify-able fneg constant expression. Check that the created -// bitcode file can be disassembled and has the constant expressions simplified. +// containing a simplify-able fneg constant expression. // // CHECK-LABEL define i32 @main() // CHECK: entry: @@ -11,7 +10,9 @@ // CHECK-NEXT: store i32 0, i32* %retval // CHECK-NEXT: [[LV:%.*]] = load float*, float** @c // CHECK-NEXT: store float 1.00e+00, float* [[LV]], align 4 -// CHECK-NEXT: ret i32 -1 +// CHECK-NEXT: [[FNEG:%.*]] = fneg float 1.00e+00 +// CHECK-NEXT: [[CONV:%.*]] = fptosi float [[FNEG]] to i32 +// CHECK-NEXT: ret i32 [[CONV]] int a[], b; float *c; diff --git a/llvm/include/llvm/Analysis/TargetFolder.h b/llvm/include/llvm/Analysis/TargetFolder.h index c42577330e9b4..db7eda54b5c45 100644 --- a/llvm/include/llvm/Analysis/TargetFolder.h +++ b/llvm/include/llvm/Analysis/TargetFolder.h @@ -110,7 +110,7 @@ class TargetFolder final : public IRBuilderFolder { Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, FastMathFlags FMF) const override { if (Constant *C = dyn_cast(V)) - return Fold(ConstantExpr::get(Opc, C)); + return ConstantFoldUnaryOpOperand(Opc, C, DL); return nullptr; } diff --git a/llvm/include/llvm/IR/ConstantFolder.h b/llvm/include/llvm/IR/ConstantFolder.h index bd28ff87965dd..82c07d47a1930 100644 --- a/llvm/include/llvm/IR/ConstantFolder.h +++ b/llvm/include/llvm/IR/ConstantFolder.h @@ -91,7 +91,7 @@ class ConstantFolder final : public IRBuilderFolder { Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, FastMathFlags FMF) const override { if (Constant *C = dyn_cast(V)) - return ConstantExpr::get(Opc, C); + return ConstantFoldUnaryInstruction(Opc, C); return nullptr; } diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 9187d49ca7a5a..df1a9bfa3da27 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1333,7 +1333,7 @@ Constant *llvm::ConstantFoldUnaryOpOperand(unsigned Opcode, Constant *Op, const DataLayout &DL) { assert(Instruction::isUnaryOp(Opcode)); - return ConstantExpr::get(Opcode, Op); + return ConstantFoldUnaryInstruction(Opcode, Op); } Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, diff --git a/llvm/test/Transforms/InstCombine/fmul.ll b/llvm/test/Transforms/InstCombine/fmul.ll index 10c8bdd532817..981e26c4912bf 100644 --- a/llvm/test/Transforms/InstCombine/fmul.ll +++ b/llvm/test/Transforms/InstCombine/fmul.ll @@ -1057,7 +1057,8 @@ define float @fmul_fdiv_factor_extra_use(float %x, float %y) { define double @fmul_negated_constant_expression(double %x) { ; CHECK-LABEL: @fmul_negated_constant_expression( -; CHECK-NEXT:[[R:%.*]] = fmul double [[X:%.*]], fneg (double bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double)) +; CHECK-NEXT:[[FSUB:%.*]] = fneg double bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double) +; CHECK-NEXT:[[R:%.*]] = fmul double [[FSUB]], [[X:%.*]] ; CHECK-NEXT:ret double [[R]] ; %fsub = fsub double -0.00e+00, bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double) diff --git a/llvm/test/Transforms/InstCombine/fneg.ll b/llvm/test/Transforms/InstCombine/fneg.ll index c08ac44e34130..08ced4018483b 100644 --- a/llvm/test/Transforms/InstCombine/fneg.ll +++ b/llvm/test/Transforms/InstCombine/
[clang] fd24750 - Revert "C++/ObjC++: switch to gnu++17 as the default standard"
Author: Nikita Popov Date: 2022-09-08T09:45:50+02:00 New Revision: fd2475049e882e6c70a745cbe0799749ba184910 URL: https://github.com/llvm/llvm-project/commit/fd2475049e882e6c70a745cbe0799749ba184910 DIFF: https://github.com/llvm/llvm-project/commit/fd2475049e882e6c70a745cbe0799749ba184910.diff LOG: Revert "C++/ObjC++: switch to gnu++17 as the default standard" This reverts commit e321c8dd2cea8365045ed44ae1c3c00c6a977d2e. This causes many failures in llvm-test-suite, for example: /home/npopov/repos/llvm-test-suite/build-O3/tools/timeit --summary MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o.time /home/npopov/repos/llvm-project/build/bin/clang++ -DNDEBUG -I/home/npopov/repos/llvm-test-suite/MultiSource/Applications/lambda-0.1.3 -O3 -w -Werror=date-time -MD -MT MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o -MF MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o.d -o MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o -c /home/npopov/repos/llvm-test-suite/MultiSource/Applications/lambda-0.1.3/token_stream.cc /home/npopov/repos/llvm-test-suite/MultiSource/Applications/lambda-0.1.3/token_stream.cc:192:2: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister] register char chr; ^ Added: clang/test/Preprocessor/lang-std.cu Modified: clang/docs/ReleaseNotes.rst clang/lib/Basic/LangStandards.cpp clang/test/lit.cfg.py clang/test/lit.site.cfg.py.in Removed: clang/test/Preprocessor/lang-std.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 425135d746b99..b370d23856c21 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -200,10 +200,6 @@ C++ Language Changes in Clang - Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` option to get the old partial ordering behavior regarding packs. -- Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of ``gnu++14``. - This means Clang will by default accept code using features from C++17 and - conforming GNU extensions. Projects incompatible with C++17 can add - ``-std=gnu++14`` to their build settings to restore the previous behaviour. C++20 Feature Support ^ diff --git a/clang/lib/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp index 92e8ab347dda1..a21898dd3c627 100644 --- a/clang/lib/Basic/LangStandards.cpp +++ b/clang/lib/Basic/LangStandards.cpp @@ -75,9 +75,10 @@ LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang, if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified) return CLANG_DEFAULT_STD_CXX; -if (T.isPS()) +if (T.isDriverKit()) + return LangStandard::lang_gnucxx17; +else return LangStandard::lang_gnucxx14; -return LangStandard::lang_gnucxx17; case Language::RenderScript: return LangStandard::lang_c99; case Language::HIP: diff --git a/clang/test/Preprocessor/lang-std.cpp b/clang/test/Preprocessor/lang-std.cpp deleted file mode 100644 index 538f1b1976dad..0 --- a/clang/test/Preprocessor/lang-std.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// UNSUPPORTED: default-std-cxx, ps4, ps5 -/// Test default standards when CLANG_DEFAULT_STD_CXX is unspecified. -/// PS4/PS5 default to gnu++14. - -// RUN: %clang_cc1 -dM -E %s | FileCheck --check-prefix=CXX17 %s -// RUN: %clang_cc1 -dM -E -x cuda %s | FileCheck --check-prefix=CXX14 %s -// RUN: %clang_cc1 -dM -E -x hip %s | FileCheck --check-prefix=CXX14 %s - -// RUN: %clang_cc1 -dM -E -x cuda -std=c++14 %s | FileCheck --check-prefix=CXX14 %s -// RUN: %clang_cc1 -dM -E -x hip -std=c++98 %s | FileCheck --check-prefix=CXX98 %s - -// CXX98: #define __cplusplus 199711L -// CXX14: #define __cplusplus 201402L -// CXX17: #define __cplusplus 201703L diff --git a/clang/test/Preprocessor/lang-std.cu b/clang/test/Preprocessor/lang-std.cu new file mode 100644 index 0..4f35af01aaf5f --- /dev/null +++ b/clang/test/Preprocessor/lang-std.cu @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -dM -E -x hip %s | FileCheck -check-prefix=CXX14 %s +// RUN: %clang_cc1 -dM -E %s | FileCheck -check-prefix=CXX14 %s +// RUN: %clang_cc1 -dM -E -std=c++98 -x hip %s | FileCheck -check-prefix=CXX98 %s +// RUN: %clang_cc1 -dM -E -std=c++98 %s | FileCheck -check-prefix=CXX98 %s + +// CXX98: #define __cplusplus 199711L +// CXX14: #define __cplusplus 201402L diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py index 7fa46e3d99fca..792216595d3fe 100644 --- a/clang/test/lit.cfg.py +++ b/clang/test/lit.cfg.py @@ -131,9 +131,6 @@ def have_host_jit_feature_support(feature_name): if config.clang_enable_opaque_pointers: config.available_features.add('enable-opaque-pointers') -if config.clang_default_std_cxx != '': -config.
[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)
nikic wrote: You also need to replace uses in polly. https://github.com/llvm/llvm-project/pull/71029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang-tools-extra] [llvm] [clang] [InferAddressSpaces] Fix constant replace to avoid modifying other functions (PR #70611)
@@ -334,6 +335,15 @@ template<> struct simplify_type { } }; +template <> struct GraphTraits { nikic wrote: > What's the issue with putting this here? Seems nicer than inlining yet > another DFS in another place. I have a couple of concerns about exposing it here. The first is that "DFS walk on `User *`" is not a well-defined operation. You can perform a DFS walk either in the direction of users or in the direction of operands. Keep in mind that, despite the name, the defining property of a `User` is that it has operands, not that it has users. Having users is a property of `Value *`. The second is that even if we say that it should be a walk in the direction of users, we still have the choice between doing the walk on `User *` or on `Use &`. The third is that doing an unbounded DFS walk on values is just a bad idea in general, and we should not encourage it. For the specific problem here, I'd consider expanding all constant expressions in the function upfront, and then not having to deal with it. https://github.com/llvm/llvm-project/pull/70611 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstCombine] Infer zext nneg flag (PR #71534)
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/71534 >From e965141dc8e0be4dceb3e302ea91761203015c72 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 6 Nov 2023 17:28:11 +0100 Subject: [PATCH] [InstCombine] Infer zext nneg flag Use KnownBits to infer the nneg flag on zext instructions. --- clang/test/Headers/wasm.c | 6 ++--- .../InstCombine/InstCombineCasts.cpp | 5 .../InstCombine/2010-11-01-lshr-mask.ll | 2 +- .../X86/x86-vector-shifts-inseltpoison.ll | 6 ++--- .../InstCombine/X86/x86-vector-shifts.ll | 10 +++ .../InstCombine/adjust-for-minmax.ll | 4 +-- .../test/Transforms/InstCombine/and-narrow.ll | 8 +++--- .../test/Transforms/InstCombine/and-xor-or.ll | 2 +- llvm/test/Transforms/InstCombine/and.ll | 18 ++--- .../InstCombine/assoc-cast-assoc.ll | 4 +-- .../test/Transforms/InstCombine/binop-cast.ll | 2 +- .../Transforms/InstCombine/cast-mul-select.ll | 20 +++--- llvm/test/Transforms/InstCombine/cast.ll | 18 ++--- llvm/test/Transforms/InstCombine/ctpop.ll | 4 +-- llvm/test/Transforms/InstCombine/cttz.ll | 8 +++--- llvm/test/Transforms/InstCombine/fmul.ll | 2 +- llvm/test/Transforms/InstCombine/freeze.ll| 26 +-- .../InstCombine/load-bitcast-select.ll| 2 +- llvm/test/Transforms/InstCombine/lshr.ll | 10 +++ .../Transforms/InstCombine/minmax-fold.ll | 2 +- .../InstCombine/minmax-intrinsics.ll | 2 +- .../Transforms/InstCombine/narrow-math.ll | 10 +++ .../Transforms/InstCombine/negated-bitmask.ll | 4 +-- .../Transforms/InstCombine/overflow-mul.ll| 2 +- .../InstCombine/reduction-add-sext-zext-i1.ll | 6 ++--- .../InstCombine/reduction-xor-sext-zext-i1.ll | 4 +-- llvm/test/Transforms/InstCombine/rem.ll | 2 +- .../InstCombine/select-bitext-bitwise-ops.ll | 8 +++--- .../Transforms/InstCombine/select-bitext.ll | 4 +-- .../InstCombine/select-cmp-cttz-ctlz.ll | 18 ++--- .../InstCombine/select-ctlz-to-cttz.ll| 4 +-- .../InstCombine/select-obo-peo-ops.ll | 16 ++-- .../InstCombine/select-with-bitwise-ops.ll| 8 +++--- ...ociation-in-bittest-with-truncation-shl.ll | 8 +++--- llvm/test/Transforms/InstCombine/shift.ll | 2 +- .../InstCombine/trunc-inseltpoison.ll | 20 +++--- llvm/test/Transforms/InstCombine/trunc.ll | 20 +++--- .../Transforms/InstCombine/udiv-simplify.ll | 2 +- .../InstCombine/udivrem-change-width.ll | 22 .../InstCombine/vector-casts-inseltpoison.ll | 2 +- .../Transforms/InstCombine/vector-casts.ll| 2 +- llvm/test/Transforms/InstCombine/wcslen-1.ll | 2 +- llvm/test/Transforms/InstCombine/wcslen-3.ll | 2 +- .../InstCombine/zeroext-and-reduce.ll | 2 +- .../Transforms/InstCombine/zext-or-icmp.ll| 10 +++ llvm/test/Transforms/InstCombine/zext.ll | 2 +- .../LoopVectorize/ARM/mve-reductions.ll | 4 +-- .../LoopVectorize/reduction-inloop.ll | 10 +++ 48 files changed, 181 insertions(+), 176 deletions(-) diff --git a/clang/test/Headers/wasm.c b/clang/test/Headers/wasm.c index a755499c6c79775..9643cafc1ce6c31 100644 --- a/clang/test/Headers/wasm.c +++ b/clang/test/Headers/wasm.c @@ -2183,7 +2183,7 @@ uint32_t test_i64x2_bitmask(v128_t a) { // CHECK-NEXT: entry: // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x i64> // CHECK-NEXT:[[TMP1:%.*]] = and i32 [[B:%.*]], 63 -// CHECK-NEXT:[[REM_I:%.*]] = zext i32 [[TMP1]] to i64 +// CHECK-NEXT:[[REM_I:%.*]] = zext nneg i32 [[TMP1]] to i64 // CHECK-NEXT:[[SPLAT_SPLATINSERT_I:%.*]] = insertelement <2 x i64> poison, i64 [[REM_I]], i64 0 // CHECK-NEXT:[[SPLAT_SPLAT_I:%.*]] = shufflevector <2 x i64> [[SPLAT_SPLATINSERT_I]], <2 x i64> poison, <2 x i32> zeroinitializer // CHECK-NEXT:[[SHL_I:%.*]] = shl <2 x i64> [[TMP0]], [[SPLAT_SPLAT_I]] @@ -2198,7 +2198,7 @@ v128_t test_i64x2_shl(v128_t a, uint32_t b) { // CHECK-NEXT: entry: // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x i64> // CHECK-NEXT:[[TMP1:%.*]] = and i32 [[B:%.*]], 63 -// CHECK-NEXT:[[REM_I:%.*]] = zext i32 [[TMP1]] to i64 +// CHECK-NEXT:[[REM_I:%.*]] = zext nneg i32 [[TMP1]] to i64 // CHECK-NEXT:[[SPLAT_SPLATINSERT_I:%.*]] = insertelement <2 x i64> poison, i64 [[REM_I]], i64 0 // CHECK-NEXT:[[SPLAT_SPLAT_I:%.*]] = shufflevector <2 x i64> [[SPLAT_SPLATINSERT_I]], <2 x i64> poison, <2 x i32> zeroinitializer // CHECK-NEXT:[[SHR_I:%.*]] = ashr <2 x i64> [[TMP0]], [[SPLAT_SPLAT_I]] @@ -2213,7 +2213,7 @@ v128_t test_i64x2_shr(v128_t a, uint32_t b) { // CHECK-NEXT: entry: // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x i64> // CHECK-NEXT:[[TMP1:%.*]] = and i32 [[B:%.*]], 63 -// CHECK-NEXT:[[REM_I:%.*]] = zext i32 [[TMP1]] to i64 +// CHECK-NEXT:
[llvm] [clang] [InstCombine] Infer zext nneg flag (PR #71534)
https://github.com/nikic closed https://github.com/llvm/llvm-project/pull/71534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)
@@ -5587,11 +5587,20 @@ Instruction *InstCombinerImpl::foldICmpWithZextOrSext(ICmpInst &ICmp) { return new ICmpInst(ICmp.getPredicate(), Builder.CreateOr(X, Y), Constant::getNullValue(X->getType())); + // Treat "zext nneg" as "sext" + auto *NonNegInst0 = dyn_cast(ICmp.getOperand(0)); + auto *NonNegInst1 = dyn_cast(ICmp.getOperand(1)); + + bool IsNonNeg0 = NonNegInst0 && NonNegInst0->hasNonNeg(); + bool IsNonNeg1 = NonNegInst1 && NonNegInst1->hasNonNeg(); + // If we have mismatched casts, treat the zext of a non-negative source as // a sext to simulate matching casts. Otherwise, we are done. // TODO: Can we handle some predicates (equality) without non-negative? - if ((IsZext0 && isKnownNonNegative(X, DL, 0, &AC, &ICmp, &DT)) || - (IsZext1 && isKnownNonNegative(Y, DL, 0, &AC, &ICmp, &DT))) + if ((IsZext0 && + (IsNonNeg0 || isKnownNonNegative(X, DL, 0, &AC, &ICmp, &DT))) || nikic wrote: After rebasing over https://github.com/llvm/llvm-project/commit/5918f62301788b53e7d3a23f3203c483e9d4d791 it's possible to drop the isKnownNonNegative() call here entirely. We should only check for zext nneg. https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)
@@ -0,0 +1,126 @@ +; RUN: opt < %s --O3 -S | FileCheck %s + +define signext i16 @vecreduce_smax_v2i16(i32 noundef %0, ptr noundef %1) #0 { nikic wrote: I think the point of these tests is to check interaction between IPSCCP and InstCombine, so a PhaseOrdering test makes sense. However, in the current form these tests are too hard to understand. I would suggest getting the IR again with `-fno-discard-value-names` and then running `opt -S -passes=sroa` over it to convert it into SSA form. https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)
@@ -0,0 +1,175 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3 +; See PR-70845 for more details +; RUN: opt < %s -S -passes=instcombine | FileCheck %s + + +define signext i32 @sext_sext(i16 %x, i16 %y) { nikic wrote: Generally the tests in this file are not right for InstCombine. We should just directly check the min/max pattern with zext nneg there, nothing more. Preferably directly next to the existing tests for the transform (you can find them by commenting out the transform and seeing which tests break). https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [InstCombine] Infer zext nneg flag (PR #71534)
nikic wrote: It looks like simplifyAssocCastAssoc() is the problematic transform. It modifies a zext in-place without clearing poison flags. https://github.com/llvm/llvm-project/pull/71534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstCombine] Infer zext nneg flag (PR #71534)
nikic wrote: Should be fixed by https://github.com/llvm/llvm-project/commit/1b1c81772fe50a1cb2b2adf8d8cf442c0b73602f. https://github.com/llvm/llvm-project/pull/71534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cd7ba9f - [Clang] Generate test checks (NFC)
Author: Nikita Popov Date: 2023-11-10T16:27:37+01:00 New Revision: cd7ba9f3d090afb5d3b15b0dcf379d15d1e11e33 URL: https://github.com/llvm/llvm-project/commit/cd7ba9f3d090afb5d3b15b0dcf379d15d1e11e33 DIFF: https://github.com/llvm/llvm-project/commit/cd7ba9f3d090afb5d3b15b0dcf379d15d1e11e33.diff LOG: [Clang] Generate test checks (NFC) Added: Modified: clang/test/Analysis/builtin_signbit.cpp Removed: diff --git a/clang/test/Analysis/builtin_signbit.cpp b/clang/test/Analysis/builtin_signbit.cpp index 251391952f9c586..a0bf7a45be1302b 100644 --- a/clang/test/Analysis/builtin_signbit.cpp +++ b/clang/test/Analysis/builtin_signbit.cpp @@ -1,46 +1,113 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3 // RUN: %clang -target powerpc-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \ -// RUN: -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE +// RUN: -O0 %s -o - | FileCheck %s --check-prefixes=CHECK-BE32 // RUN: %clang -target powerpc64-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \ -// RUN: -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE +// RUN: -O0 %s -o - | FileCheck %s --check-prefixes=CHECK-BE64 // RUN: %clang -target powerpc64le-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \ -// RUN: -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-LE +// RUN: -O0 %s -o - | FileCheck %s --check-prefixes=CHECK-LE bool b; double d = -1.0; long double ld = -1.0L; +// CHECK-BE32-LABEL: define dso_local void @_Z12test_signbitv( +// CHECK-BE32-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK-BE32-NEXT: entry: +// CHECK-BE32-NEXT:[[FROMBOOL:%.*]] = zext i1 icmp slt (i64 trunc (i128 lshr (i128 bitcast (ppc_fp128 0xM3FF0 to i128), i128 64) to i64), i64 0) to i8 +// CHECK-BE32-NEXT:store i8 [[FROMBOOL]], ptr @b, align 1 +// CHECK-BE32-NEXT:[[TMP0:%.*]] = load ppc_fp128, ptr @ld, align 16 +// CHECK-BE32-NEXT:[[TMP1:%.*]] = bitcast ppc_fp128 [[TMP0]] to i128 +// CHECK-BE32-NEXT:[[TMP2:%.*]] = lshr i128 [[TMP1]], 64 +// CHECK-BE32-NEXT:[[TMP3:%.*]] = trunc i128 [[TMP2]] to i64 +// CHECK-BE32-NEXT:[[TMP4:%.*]] = icmp slt i64 [[TMP3]], 0 +// CHECK-BE32-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP4]] to i8 +// CHECK-BE32-NEXT:store i8 [[FROMBOOL1]], ptr @b, align 1 +// CHECK-BE32-NEXT:store i8 0, ptr @b, align 1 +// CHECK-BE32-NEXT:[[TMP5:%.*]] = load double, ptr @d, align 8 +// CHECK-BE32-NEXT:[[CONV:%.*]] = fptrunc double [[TMP5]] to float +// CHECK-BE32-NEXT:[[TMP6:%.*]] = bitcast float [[CONV]] to i32 +// CHECK-BE32-NEXT:[[TMP7:%.*]] = icmp slt i32 [[TMP6]], 0 +// CHECK-BE32-NEXT:[[FROMBOOL2:%.*]] = zext i1 [[TMP7]] to i8 +// CHECK-BE32-NEXT:store i8 [[FROMBOOL2]], ptr @b, align 1 +// CHECK-BE32-NEXT:[[FROMBOOL3:%.*]] = zext i1 icmp slt (i64 trunc (i128 lshr (i128 bitcast (ppc_fp128 0xM3FF0 to i128), i128 64) to i64), i64 0) to i8 +// CHECK-BE32-NEXT:store i8 [[FROMBOOL3]], ptr @b, align 1 +// CHECK-BE32-NEXT:[[TMP8:%.*]] = load ppc_fp128, ptr @ld, align 16 +// CHECK-BE32-NEXT:[[TMP9:%.*]] = bitcast ppc_fp128 [[TMP8]] to i128 +// CHECK-BE32-NEXT:[[TMP10:%.*]] = lshr i128 [[TMP9]], 64 +// CHECK-BE32-NEXT:[[TMP11:%.*]] = trunc i128 [[TMP10]] to i64 +// CHECK-BE32-NEXT:[[TMP12:%.*]] = icmp slt i64 [[TMP11]], 0 +// CHECK-BE32-NEXT:[[FROMBOOL4:%.*]] = zext i1 [[TMP12]] to i8 +// CHECK-BE32-NEXT:store i8 [[FROMBOOL4]], ptr @b, align 1 +// CHECK-BE32-NEXT:ret void +// +// CHECK-BE64-LABEL: define dso_local void @_Z12test_signbitv( +// CHECK-BE64-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK-BE64-NEXT: entry: +// CHECK-BE64-NEXT:[[FROMBOOL:%.*]] = zext i1 icmp slt (i64 trunc (i128 lshr (i128 bitcast (ppc_fp128 0xM3FF0 to i128), i128 64) to i64), i64 0) to i8 +// CHECK-BE64-NEXT:store i8 [[FROMBOOL]], ptr @b, align 1 +// CHECK-BE64-NEXT:[[TMP0:%.*]] = load ppc_fp128, ptr @ld, align 16 +// CHECK-BE64-NEXT:[[TMP1:%.*]] = bitcast ppc_fp128 [[TMP0]] to i128 +// CHECK-BE64-NEXT:[[TMP2:%.*]] = lshr i128 [[TMP1]], 64 +// CHECK-BE64-NEXT:[[TMP3:%.*]] = trunc i128 [[TMP2]] to i64 +// CHECK-BE64-NEXT:[[TMP4:%.*]] = icmp slt i64 [[TMP3]], 0 +// CHECK-BE64-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP4]] to i8 +// CHECK-BE64-NEXT:store i8 [[FROMBOOL1]], ptr @b, align 1 +// CHECK-BE64-NEXT:store i8 0, ptr @b, align 1 +// CHECK-BE64-NEXT:[[TMP5:%.*]] = load double, ptr @d, align 8 +// CHECK-BE64-NEXT:[[CONV:%.*]] = fptrunc double [[TMP5]] to float +// CHECK-BE64-NEXT:[[TMP6:%.*]] = bitcast float [[CONV]] to i32 +// CHECK-BE64-NEXT:[[TMP7:%.*]] = icmp slt i32 [[TMP6]], 0 +// CHECK-BE64-NEXT:[[FROMBOOL2:%.*]] = zext i1 [[TMP7]] to i8 +// CHECK-BE64-NEXT:store i8 [[FROMBOOL2]], ptr @b, align 1 +// CHECK-BE64-NEXT:[[FROMBOOL3:%.*]] = zext
[clang] 82f68a9 - [IR] Mark lshr and ashr constant expressions as undesirable
Author: Nikita Popov Date: 2023-11-10T16:29:13+01:00 New Revision: 82f68a992b9f89036042d57a5f6345cb2925b2c1 URL: https://github.com/llvm/llvm-project/commit/82f68a992b9f89036042d57a5f6345cb2925b2c1 DIFF: https://github.com/llvm/llvm-project/commit/82f68a992b9f89036042d57a5f6345cb2925b2c1.diff LOG: [IR] Mark lshr and ashr constant expressions as undesirable These will no longer be created by default during constant folding. Added: Modified: clang/test/Analysis/builtin_signbit.cpp llvm/lib/IR/Constants.cpp llvm/test/CodeGen/AArch64/stack-tagging-initializer-merge.ll Removed: diff --git a/clang/test/Analysis/builtin_signbit.cpp b/clang/test/Analysis/builtin_signbit.cpp index a0bf7a45be1302b..e02802c5a514b0b 100644 --- a/clang/test/Analysis/builtin_signbit.cpp +++ b/clang/test/Analysis/builtin_signbit.cpp @@ -12,60 +12,72 @@ long double ld = -1.0L; // CHECK-BE32-LABEL: define dso_local void @_Z12test_signbitv( // CHECK-BE32-SAME: ) #[[ATTR0:[0-9]+]] { // CHECK-BE32-NEXT: entry: -// CHECK-BE32-NEXT:[[FROMBOOL:%.*]] = zext i1 icmp slt (i64 trunc (i128 lshr (i128 bitcast (ppc_fp128 0xM3FF0 to i128), i128 64) to i64), i64 0) to i8 +// CHECK-BE32-NEXT:[[TMP0:%.*]] = lshr i128 bitcast (ppc_fp128 0xM3FF0 to i128), 64 +// CHECK-BE32-NEXT:[[TMP1:%.*]] = trunc i128 [[TMP0]] to i64 +// CHECK-BE32-NEXT:[[TMP2:%.*]] = icmp slt i64 [[TMP1]], 0 +// CHECK-BE32-NEXT:[[FROMBOOL:%.*]] = zext i1 [[TMP2]] to i8 // CHECK-BE32-NEXT:store i8 [[FROMBOOL]], ptr @b, align 1 -// CHECK-BE32-NEXT:[[TMP0:%.*]] = load ppc_fp128, ptr @ld, align 16 -// CHECK-BE32-NEXT:[[TMP1:%.*]] = bitcast ppc_fp128 [[TMP0]] to i128 -// CHECK-BE32-NEXT:[[TMP2:%.*]] = lshr i128 [[TMP1]], 64 -// CHECK-BE32-NEXT:[[TMP3:%.*]] = trunc i128 [[TMP2]] to i64 -// CHECK-BE32-NEXT:[[TMP4:%.*]] = icmp slt i64 [[TMP3]], 0 -// CHECK-BE32-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP4]] to i8 +// CHECK-BE32-NEXT:[[TMP3:%.*]] = load ppc_fp128, ptr @ld, align 16 +// CHECK-BE32-NEXT:[[TMP4:%.*]] = bitcast ppc_fp128 [[TMP3]] to i128 +// CHECK-BE32-NEXT:[[TMP5:%.*]] = lshr i128 [[TMP4]], 64 +// CHECK-BE32-NEXT:[[TMP6:%.*]] = trunc i128 [[TMP5]] to i64 +// CHECK-BE32-NEXT:[[TMP7:%.*]] = icmp slt i64 [[TMP6]], 0 +// CHECK-BE32-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP7]] to i8 // CHECK-BE32-NEXT:store i8 [[FROMBOOL1]], ptr @b, align 1 // CHECK-BE32-NEXT:store i8 0, ptr @b, align 1 -// CHECK-BE32-NEXT:[[TMP5:%.*]] = load double, ptr @d, align 8 -// CHECK-BE32-NEXT:[[CONV:%.*]] = fptrunc double [[TMP5]] to float -// CHECK-BE32-NEXT:[[TMP6:%.*]] = bitcast float [[CONV]] to i32 -// CHECK-BE32-NEXT:[[TMP7:%.*]] = icmp slt i32 [[TMP6]], 0 -// CHECK-BE32-NEXT:[[FROMBOOL2:%.*]] = zext i1 [[TMP7]] to i8 +// CHECK-BE32-NEXT:[[TMP8:%.*]] = load double, ptr @d, align 8 +// CHECK-BE32-NEXT:[[CONV:%.*]] = fptrunc double [[TMP8]] to float +// CHECK-BE32-NEXT:[[TMP9:%.*]] = bitcast float [[CONV]] to i32 +// CHECK-BE32-NEXT:[[TMP10:%.*]] = icmp slt i32 [[TMP9]], 0 +// CHECK-BE32-NEXT:[[FROMBOOL2:%.*]] = zext i1 [[TMP10]] to i8 // CHECK-BE32-NEXT:store i8 [[FROMBOOL2]], ptr @b, align 1 -// CHECK-BE32-NEXT:[[FROMBOOL3:%.*]] = zext i1 icmp slt (i64 trunc (i128 lshr (i128 bitcast (ppc_fp128 0xM3FF0 to i128), i128 64) to i64), i64 0) to i8 +// CHECK-BE32-NEXT:[[TMP11:%.*]] = lshr i128 bitcast (ppc_fp128 0xM3FF0 to i128), 64 +// CHECK-BE32-NEXT:[[TMP12:%.*]] = trunc i128 [[TMP11]] to i64 +// CHECK-BE32-NEXT:[[TMP13:%.*]] = icmp slt i64 [[TMP12]], 0 +// CHECK-BE32-NEXT:[[FROMBOOL3:%.*]] = zext i1 [[TMP13]] to i8 // CHECK-BE32-NEXT:store i8 [[FROMBOOL3]], ptr @b, align 1 -// CHECK-BE32-NEXT:[[TMP8:%.*]] = load ppc_fp128, ptr @ld, align 16 -// CHECK-BE32-NEXT:[[TMP9:%.*]] = bitcast ppc_fp128 [[TMP8]] to i128 -// CHECK-BE32-NEXT:[[TMP10:%.*]] = lshr i128 [[TMP9]], 64 -// CHECK-BE32-NEXT:[[TMP11:%.*]] = trunc i128 [[TMP10]] to i64 -// CHECK-BE32-NEXT:[[TMP12:%.*]] = icmp slt i64 [[TMP11]], 0 -// CHECK-BE32-NEXT:[[FROMBOOL4:%.*]] = zext i1 [[TMP12]] to i8 +// CHECK-BE32-NEXT:[[TMP14:%.*]] = load ppc_fp128, ptr @ld, align 16 +// CHECK-BE32-NEXT:[[TMP15:%.*]] = bitcast ppc_fp128 [[TMP14]] to i128 +// CHECK-BE32-NEXT:[[TMP16:%.*]] = lshr i128 [[TMP15]], 64 +// CHECK-BE32-NEXT:[[TMP17:%.*]] = trunc i128 [[TMP16]] to i64 +// CHECK-BE32-NEXT:[[TMP18:%.*]] = icmp slt i64 [[TMP17]], 0 +// CHECK-BE32-NEXT:[[FROMBOOL4:%.*]] = zext i1 [[TMP18]] to i8 // CHECK-BE32-NEXT:store i8 [[FROMBOOL4]], ptr @b, align 1 // CHECK-BE32-NEXT:ret void // // CHECK-BE64-LABEL: define dso_local void @_Z12test_signbitv( // CHECK-BE64-SAME: ) #[[ATTR0:[0-9]+]] { // CHECK-BE64-NEXT: entry: -// CHECK-BE6
[clang] 3a9cc17 - [Clang] Add missing REQUIRES to tests (NFC)
Author: Nikita Popov Date: 2023-11-10T16:31:38+01:00 New Revision: 3a9cc17ca088267348e4b4a6e64a88a38ae9c6e4 URL: https://github.com/llvm/llvm-project/commit/3a9cc17ca088267348e4b4a6e64a88a38ae9c6e4 DIFF: https://github.com/llvm/llvm-project/commit/3a9cc17ca088267348e4b4a6e64a88a38ae9c6e4.diff LOG: [Clang] Add missing REQUIRES to tests (NFC) Added: Modified: clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_max.c clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_min.c Removed: diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_max.c b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_max.c index 31f2240dd41104e..762a98b39012559 100644 --- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_max.c +++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_max.c @@ -4,6 +4,7 @@ // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s +// REQUIRES: aarch64-registered-target #include #ifdef SVE_OVERLOADED_FORMS diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_min.c b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_min.c index 05465c7f17a9e1a..c5f2f0c65576a5f 100644 --- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_min.c +++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_min.c @@ -4,6 +4,7 @@ // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s +// REQUIRES: aarch64-registered-target #include #ifdef SVE_OVERLOADED_FORMS ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][SME2] Add single and multi min and max builtins (PR #71688)
nikic wrote: FYI I pushed https://github.com/llvm/llvm-project/commit/3a9cc17ca088267348e4b4a6e64a88a38ae9c6e4 to hopefully unbreak the build. https://github.com/llvm/llvm-project/pull/71688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)
@@ -247,6 +355,19 @@ define i1 @sext_zext_uge_op0_wide(i16 %x, i8 %y) { ret i1 %c } + +define i1 @sext_zext_nneg_uge_op0_wide(i16 %x, i8 %y) { +; CHECK-LABEL: @sext_zext_nneg_uge_op0_wide( +; CHECK-NEXT:[[TMP1:%.*]] = sext i8 [[Y:%.*]] to i16 +; CHECK-NEXT:[[C:%.*]] = icmp ule i16 [[TMP1]], [[X:%.*]] +; CHECK-NEXT:ret i1 [[C]] +; + %a = sext i16 %x to i32 + %b = zext nneg i8 %y to i32 + %c = icmp uge i32 %a, %b + ret i1 %c +} + define i1 @zext_sext_sgt_known_nonneg(i8 %x, i8 %y) { ; CHECK-LABEL: @zext_sext_sgt_known_nonneg( nikic wrote: Yeah, these tests are largely redundant now. We could delete them, but I think it's also okay to keep them to show the combination of nneg inference and this fold. https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)
@@ -0,0 +1,145 @@ +; RUN: opt < %s --O3 -S | FileCheck %s nikic wrote: You need to use `-O2 -Xclang -disable-llvm-optzns`, or manually drop the `optnone` attributes. https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)
nikic wrote: Your original example does not verify: https://alive2.llvm.org/ce/z/Bkd89Z Can you please provide a correct example of what you're trying to do? https://github.com/llvm/llvm-project/pull/68502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstCombine] Use zext's nneg flag for icmp folding (PR #70845)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [clang-tools-extra] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)
nikic wrote: Yes, I understand that this transform is only a step towards handling the full pattern. I'm asking for a complete, working example of the original motivating case. The snippets posted in https://github.com/llvm/llvm-project/pull/68502#discussion_r1351618002 do not appear to be correct, or I failed to assemble them correctly. Please provide complete src and tgt functions that verify with alive2. https://github.com/llvm/llvm-project/pull/68502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [clang] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)
nikic wrote: Thanks for the updated example! To explain what I meant in first comment using this example: We would perform the transform https://alive2.llvm.org/ce/z/nllcB_, which does not depend at all on how `%yx` is constructed, and whether there is any way to form the `fshl` separately. If the `%yx` is appropriately constructed, the `fshl` can be removed (https://alive2.llvm.org/ce/z/B_KOwv, another missing transform). Is this not a viable approach? Is there a concern here that generating both fshl and bitreverse may be non-profitable for targets without bitreverse? Or maybe supporting this makes the matching too expensive? https://github.com/llvm/llvm-project/pull/68502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1b36a9f - [clang] Use clang_cc1 in test (NFC)
Author: Nikita Popov Date: 2023-11-13T12:37:14+01:00 New Revision: 1b36a9f0b71abbf02b9bccc3c2d4fd668a68d59d URL: https://github.com/llvm/llvm-project/commit/1b36a9f0b71abbf02b9bccc3c2d4fd668a68d59d DIFF: https://github.com/llvm/llvm-project/commit/1b36a9f0b71abbf02b9bccc3c2d4fd668a68d59d.diff LOG: [clang] Use clang_cc1 in test (NFC) I believe this should avoid the requirement for an assertion-enabled build. Added: Modified: clang/test/Analysis/builtin_signbit.cpp Removed: diff --git a/clang/test/Analysis/builtin_signbit.cpp b/clang/test/Analysis/builtin_signbit.cpp index c10aebbc8d176cc..57e6816ce280218 100644 --- a/clang/test/Analysis/builtin_signbit.cpp +++ b/clang/test/Analysis/builtin_signbit.cpp @@ -1,11 +1,10 @@ // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3 -// RUN: %clang -target powerpc-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \ +// RUN: %clang_cc1 -triple powerpc-linux-gnu -emit-llvm \ // RUN: -O0 %s -o - | FileCheck %s --check-prefixes=CHECK-BE32 -// RUN: %clang -target powerpc64-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \ +// RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm \ // RUN: -O0 %s -o - | FileCheck %s --check-prefixes=CHECK-BE64 -// RUN: %clang -target powerpc64le-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \ +// RUN: %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm \ // RUN: -O0 %s -o - | FileCheck %s --check-prefixes=CHECK-LE -// REQUIRES: asserts bool b; double d = -1.0; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [flang] [DebugInfo] Move jump table test to X86 directory (PR #72118)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/72118 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [InstCombine] Infer disjoint flag on Or instructions. (PR #72912)
nikic wrote: > We don't have a `isGuaranteedNotToBeUndef` only function, so that's the only > way. I would leave a fixme, since this call can be removed if we ever manage > to kill undef. I actually added this function earlier today. > @nikic is something like this the right fix? I'd move the calls to isGuaranteedNotToBeUndef into haveNoCommonBitsSetSpecialCases, so you can check the correct values. https://github.com/llvm/llvm-project/pull/72912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)
nikic wrote: The problem for mpeg2decode seems to be that we do more `add` to `or disjoint` conversions. But `or disjoint` is still being implemented, so e.g. in SCEV we don't recognize it yet and fail to create an `add` SCEV for it. So I think we need to do some more work on `or disjoint` and then try again. https://github.com/llvm/llvm-project/pull/73662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)
nikic wrote: I've put up https://github.com/llvm/llvm-project/pull/74467 to use disjoint in SCEV. https://github.com/llvm/llvm-project/pull/73662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/73662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)
nikic wrote: Rebased over the SCEV change. @dtcxzyw Can you please give it another try? https://github.com/llvm/llvm-project/pull/73662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -98,6 +99,13 @@ class ConstantInt final : public ConstantData { /// value. Otherwise return a ConstantInt for the given value. static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false); + /// WARNING: Incomplete support, do not use. These methods exist for early + /// prototyping, for most use cases ConstantInt::get() should be used. + /// Return a ConstantInt with a splat of the given value. + static ConstantInt *getSplat(LLVMContext &Context, ElementCount EC, + const APInt &V); + static ConstantInt *getSplat(const VectorType *Ty, const APInt &V); nikic wrote: I don't think these APIs should exist. `ConstantInt::get()` *already* supports creation of splats, they just aren't represented as `ConstantInt`s. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -343,7 +343,7 @@ static bool verifyTripCount(Value *RHS, Loop *L, // If the RHS of the compare is equal to the backedge taken count we need // to add one to get the trip count. if (SCEVRHS == BackedgeTCExt || SCEVRHS == BackedgeTakenCount) { - ConstantInt *One = ConstantInt::get(ConstantRHS->getType(), 1); + ConstantInt *One = ConstantInt::get(ConstantRHS->getIntegerType(), 1); nikic wrote: Why are you changing usages like these? This code should work fine with `getType()`. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -136,7 +144,11 @@ class ConstantInt final : public ConstantData { inline const APInt &getValue() const { return Val; } /// getBitWidth - Return the bitwidth of this constant. - unsigned getBitWidth() const { return Val.getBitWidth(); } + unsigned getBitWidth() const { +assert(getType()->isIntegerTy() && + "Returning the bitwidth of a vector constant is not support!"); nikic wrote: Why? I think this API should work with vectors as well (with the current implementation, i.e. returning the bitwidth of the scalar value). You can just adjust the comment to clarify. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -98,6 +99,13 @@ class ConstantInt final : public ConstantData { /// value. Otherwise return a ConstantInt for the given value. static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false); + /// WARNING: Incomplete support, do not use. These methods exist for early + /// prototyping, for most use cases ConstantInt::get() should be used. + /// Return a ConstantInt with a splat of the given value. + static ConstantInt *getSplat(LLVMContext &Context, ElementCount EC, + const APInt &V); + static ConstantInt *getSplat(const VectorType *Ty, const APInt &V); nikic wrote: I think this isn't the right way to phase in the change. I think the `splat` syntax should just return whatever `ConstantVector::getSplat()` produces, and what that produces can be controlled by the opt flags you have introduced. That means that the splat syntax becomes usable right away as a short-hand for producing the representations we currently use, and will switch to producing plain ConstantInt/ConstantFP once the flag is flipped (or in tests that explicitly flip it). https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -136,7 +144,11 @@ class ConstantInt final : public ConstantData { inline const APInt &getValue() const { return Val; } /// getBitWidth - Return the bitwidth of this constant. - unsigned getBitWidth() const { return Val.getBitWidth(); } + unsigned getBitWidth() const { +assert(getType()->isIntegerTy() && + "Returning the bitwidth of a vector constant is not support!"); nikic wrote: IMHO this is not necessary. If the name were `getSizeInBits()` I would agree, but the term "bit width" implies that we're talking about scalar. We don't use the term "bit width" to refer to full size of a vector. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -343,7 +343,7 @@ static bool verifyTripCount(Value *RHS, Loop *L, // If the RHS of the compare is equal to the backedge taken count we need // to add one to get the trip count. if (SCEVRHS == BackedgeTCExt || SCEVRHS == BackedgeTakenCount) { - ConstantInt *One = ConstantInt::get(ConstantRHS->getType(), 1); + ConstantInt *One = ConstantInt::get(ConstantRHS->getIntegerType(), 1); nikic wrote: I don't really follow here. Even if you rename the overload on ConstantInt, there will still be the method inherited from `Value::getType()`, and using that method here should work (and be forward-compatible with vector ConstantInt), because `ConstantInt::get` doesn't actually require that the argument is an IntegerType. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -343,7 +343,7 @@ static bool verifyTripCount(Value *RHS, Loop *L, // If the RHS of the compare is equal to the backedge taken count we need // to add one to get the trip count. if (SCEVRHS == BackedgeTCExt || SCEVRHS == BackedgeTakenCount) { - ConstantInt *One = ConstantInt::get(ConstantRHS->getType(), 1); + ConstantInt *One = ConstantInt::get(ConstantRHS->getIntegerType(), 1); nikic wrote: Ooooh, I think the issue is that it's stored in a `ConstantInt *` variable. Changing it to `Constant *` should make it pick the other overload, I think. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)
nikic wrote: Okay, it looks like the mpeg2decode regression is indeed fixed. I think the only somewhat significant regression left is `Shootout-C++-ary2`, but in my IR diffs I don't see any regression there (only improvements with a bunch of conditions being optimized away). https://github.com/llvm/llvm-project/pull/73662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)
https://github.com/nikic closed https://github.com/llvm/llvm-project/pull/73662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)
nikic wrote: @bjope It looks like the InstCombine changes enable IndVars to perform LFTR, which is unprofitable in this case. Though the `umax(1)` call is actually completely unnecessary here, but SCEV doesn't realize it. I've put up https://github.com/llvm/llvm-project/pull/75039 to fix that. Does that improve things for you? https://github.com/llvm/llvm-project/pull/73662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)
nikic wrote: @yonghong-song I think it may be possible to improve CVP to handle this better, in which case we won't need BPF workarounds. I'll look into it. https://github.com/llvm/llvm-project/pull/73662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] split load to bytes to deduce load value (PR #72364)
https://github.com/nikic requested changes to this pull request. I don't like the overall approach of assembling this from individual byte-sized loads here. What I would expect to see is more something along these lines: If we find a clobbering store that a) only clobbers some subset of the loaded bytes and b) stores a constant, then try to find the next clobbering store from there, and continue doing this until we have found all the bytes being loaded. https://github.com/llvm/llvm-project/pull/72364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] split load to bytes to deduce load value (PR #72364)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/72364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] split load to bytes to deduce load value (PR #72364)
@@ -2128,6 +2129,105 @@ static void patchAndReplaceAllUsesWith(Instruction *I, Value *Repl) { I->replaceAllUsesWith(Repl); } +// split load to single byte loads and check if the value can be deduced +// +// Example: +// define i32 @f(i8* %P) +// 1: %b2 = getelementptr inbounds i8, i8* %P, i64 1 +// 2: store i8 0, i8* %b2, align 1 +// 3: store i8 0, i8* %P, align 1 +// 4: %s1 = bitcast i8* %P to i16* +// 5: %L = load i16, i16* %s1, align 4 nikic wrote: ```suggestion // define i32 @f(ptr %P) // 1: %b2 = getelementptr inbounds i8, ptr %P, i64 1 // 2: store i8 0, ptr %b2, align 1 // 3: store i8 0, ptr %P, align 1 // 5: %L = load i16, ptr %P, align 4 ``` https://github.com/llvm/llvm-project/pull/72364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] split load to bytes to deduce load value (PR #72364)
@@ -2128,6 +2129,105 @@ static void patchAndReplaceAllUsesWith(Instruction *I, Value *Repl) { I->replaceAllUsesWith(Repl); } +// split load to single byte loads and check if the value can be deduced +// +// Example: +// define i32 @f(i8* %P) +// 1: %b2 = getelementptr inbounds i8, i8* %P, i64 1 +// 2: store i8 0, i8* %b2, align 1 +// 3: store i8 0, i8* %P, align 1 +// 4: %s1 = bitcast i8* %P to i16* +// 5: %L = load i16, i16* %s1, align 4 +// +// The last clobbering write for the load is (3) but it doesn't cover the whole +// read. So AnalyzeLoadAvailability would give up. +// This function emit temporary byte-sized loads that cover the original load, +// so that any last write covers the read. We run AnalyzeLoadAvailability on +// each byte to try to construct the load as a constant. +bool GVNPass::splitAndprocessLoad(LoadInst *L) { + if (L->isAtomic()) +return false; + + Type *LTy = L->getType(); + if (!LTy->isIntegerTy()) +return false; + + unsigned BW = LTy->getIntegerBitWidth(); + if (BW % 8) +return false; + + IntegerType *ByteTy = IntegerType::getInt8Ty(LTy->getContext()); + Type *BytePtrTy = PointerType::get(ByteTy, L->getPointerAddressSpace()); + BitCastInst *Base = new BitCastInst(L->getPointerOperand(), BytePtrTy, "", L); nikic wrote: Not necessary with opaque pointers. https://github.com/llvm/llvm-project/pull/72364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] split load to bytes to deduce load value (PR #72364)
@@ -0,0 +1,166 @@ +; RUN: opt -S -O3 < %s nikic wrote: GVN tests should use `-passes=gvn` only, not `-O3`. https://github.com/llvm/llvm-project/pull/72364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] Fix CSPGO clang pass manager test (PR #72681)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/72681 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Ensure minimal alignment of global vars of incomplete type. (PR #72886)
@@ -0,0 +1,32 @@ +// RUN: %clang --target=s390x-linux -S -emit-llvm -o - %s | FileCheck %s nikic wrote: Why is this a Driver test rather than a CodeGen test using clang_cc1? https://github.com/llvm/llvm-project/pull/72886 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)
nikic wrote: The InstCombine/ptrmask.ll test is failing in CI. https://github.com/llvm/llvm-project/pull/67166 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 03ec84a - Revert "Add two time-trace scope variables."
Author: Nikita Popov Date: 2023-10-31T10:46:49+01:00 New Revision: 03ec84a00ba4d540222ab39c407e02959058fbdd URL: https://github.com/llvm/llvm-project/commit/03ec84a00ba4d540222ab39c407e02959058fbdd DIFF: https://github.com/llvm/llvm-project/commit/03ec84a00ba4d540222ab39c407e02959058fbdd.diff LOG: Revert "Add two time-trace scope variables." This reverts commit 33b85867e30e1adc2ff2173039c199b81c10f52b. This causes a large compile-time regression (about 1% for unoptimized builds). Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Parse/Parser.cpp clang/unittests/Support/TimeProfilerTest.cpp Removed: clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c151bd9d234b51e..bc28bb567f6932a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -427,14 +427,6 @@ Improvements to Clang's diagnostics (or, more commonly, ``NULL`` when the platform defines it as ``__null``) to be more consistent with GCC. -Improvements to Clang's time-trace --- -- Two time-trace scope variables are added. A time trace scope variable of - ``ParseDeclarationOrFunctionDefinition`` with the function's source location - is added to record the time spent parsing the function's declaration or - definition. Another time trace scope variable of ``ParseFunctionDefinition`` - is also added to record the name of the defined function. - Bug Fixes in This Version - - Fixed an issue where a class template specialization whose declaration is diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index bef3a0dcb285efd..0f930248e77174b 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -13,8 +13,8 @@ #include "clang/Parse/Parser.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" -#include "clang/AST/ASTLambda.h" #include "clang/AST/DeclTemplate.h" +#include "clang/AST/ASTLambda.h" #include "clang/Basic/FileManager.h" #include "clang/Parse/ParseDiagnostic.h" #include "clang/Parse/RAIIObjectsForParser.h" @@ -22,7 +22,6 @@ #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/Scope.h" #include "llvm/Support/Path.h" -#include "llvm/Support/TimeProfiler.h" using namespace clang; @@ -1230,13 +1229,6 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition( ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs, ParsingDeclSpec *DS, AccessSpecifier AS) { - // Add an enclosing time trace scope for a bunch of small scopes with - // "EvaluateAsConstExpr". - llvm::TimeTraceScope TimeScope( - "ParseDeclarationOrFunctionDefinition", - Tok.getLocation().printToString( - Actions.getASTContext().getSourceManager())); - if (DS) { return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS); } else { @@ -1267,10 +1259,6 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition( Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, const ParsedTemplateInfo &TemplateInfo, LateParsedAttrList *LateParsedAttrs) { - llvm::TimeTraceScope TimeScope( - "ParseFunctionDefinition", - Actions.GetNameForDeclarator(D).getName().getAsString()); - // Poison SEH identifiers so they are flagged as illegal in function bodies. PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); diff --git a/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp deleted file mode 100644 index f854cddadbfcc1d..000 --- a/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o %T/check-time-trace-ParseDeclarationOrFunctionDefinition %s -// RUN: cat %T/check-time-trace-ParseDeclarationOrFunctionDefinition.json \ -// RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \ -// RUN: | FileCheck %s - -// CHECK-DAG: "name": "ParseDeclarationOrFunctionDefinition" -// CHECK-DAG: "detail": "{{.*}}check-time-trace-ParseDeclarationOrFunctionDefinition.cpp:15:1" -// CHECK-DAG: "name": "ParseFunctionDefinition" -// CHECK-DAG: "detail": "foo" -// CHECK-DAG: "name": "ParseFunctionDefinition" -// CHECK-DAG: "detail": "bar" - -template -void foo(T) {} -void bar() { foo(0); } diff --git a/clang/unittests/Support/TimeProfilerTest.cpp b/clang/unittests/Support/TimeProfilerTest.cpp index 97fdbb7232b1351..a7ca2b
[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)
nikic wrote: I've reverted this change because it causes a large compile-time regression: http://llvm-compile-time-tracker.com/compare.php?from=61b9176cf70444c54f3ac6eebd82fc9ffd69944d&to=33b85867e30e1adc2ff2173039c199b81c10f52b&stat=instructions:u >From a quick glance at your implementation, I suspect the issues is that the >used strings may be expensive to compute. TimeTraceScope has an overload >accepting a closure that calculates the detail string for such cases. https://github.com/llvm/llvm-project/pull/65268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)
@@ -5587,11 +5587,17 @@ Instruction *InstCombinerImpl::foldICmpWithZextOrSext(ICmpInst &ICmp) { return new ICmpInst(ICmp.getPredicate(), Builder.CreateOr(X, Y), Constant::getNullValue(X->getType())); + // Treat "zext nneg" as "sext" + bool IsNonNeg0 = isa(ICmp.getOperand(0)); + bool IsNonNeg1 = isa(ICmp.getOperand(1)); nikic wrote: This only checks whether the instruction *can* have an nneg flag, not whether it has it. You need to check `isNonNeg()` for that. https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)
@@ -0,0 +1,185 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --tool ./bin/opt --version 3 +; See PRXXX for more details +; RUN-./bin/opt: opt < %s -S -passes=ipsccp | FileCheck %s nikic wrote: This is an ipsccp test in the InstCombine directory? https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)
@@ -0,0 +1,19 @@ +// RUN: %clang_cc1 %s -O2 -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s nikic wrote: We don't test end-to-end codegen with clang. If you want to test this, you should take the unoptimized clang IR and create a test in the llvm/test/PhaseOrdering directory using it. https://github.com/llvm/llvm-project/pull/70845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 5084891 - [CGExprConstant] Avoid use of ConstantExpr::getIntegerCast() (NFC)
Author: Nikita Popov Date: 2023-11-01T12:02:19+01:00 New Revision: 50848916e5e4f07231c7366e6d0014de6f7bc362 URL: https://github.com/llvm/llvm-project/commit/50848916e5e4f07231c7366e6d0014de6f7bc362 DIFF: https://github.com/llvm/llvm-project/commit/50848916e5e4f07231c7366e6d0014de6f7bc362.diff LOG: [CGExprConstant] Avoid use of ConstantExpr::getIntegerCast() (NFC) We're working on a ConstantInt here, so folding cannot fail. Only avoid the API use. Added: Modified: clang/lib/CodeGen/CGExprConstant.cpp Removed: diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index c46f38d651972bc..cd91a698a9336f8 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -1930,8 +1930,9 @@ ConstantLValueEmitter::tryEmitAbsolute(llvm::Type *destTy) { // FIXME: signedness depends on the original integer type. auto intptrTy = CGM.getDataLayout().getIntPtrType(destPtrTy); llvm::Constant *C; - C = llvm::ConstantExpr::getIntegerCast(getOffset(), intptrTy, - /*isSigned*/ false); + C = llvm::ConstantFoldIntegerCast(getOffset(), intptrTy, /*isSigned*/ false, +CGM.getDataLayout()); + assert(C && "Must have folded, as Offset is a ConstantInt"); C = llvm::ConstantExpr::getIntToPtr(C, destPtrTy); return C; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/67166 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)
https://github.com/nikic approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/67166 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)
@@ -978,8 +1031,10 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, } // If the client is only demanding bits that we know, return the known - // constant. - if (DemandedMask.isSubsetOf(Known.Zero|Known.One)) + // constant. We can't directly simplify pointers as a constant because of + // pointer provanance. nikic wrote: provenance https://github.com/llvm/llvm-project/pull/67166 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)
@@ -6411,6 +6411,44 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1, return Constant::getNullValue(ReturnType); break; } + case Intrinsic::ptrmask: { +if (isa(Op0) || isa(Op1)) + return PoisonValue::get(Op0->getType()); + +// NOTE: We can't apply this simplifications based on the value of Op1 +// because we need to preserve provenance. +if (Q.isUndefValue(Op0) || match(Op0, m_Zero())) + return Constant::getNullValue(Op0->getType()); + +assert(Op1->getType()->getScalarSizeInBits() == + Q.DL.getIndexTypeSizeInBits(Op0->getType()) && + "Invalid mask width"); +// If index-width (mask size) is less than pointer-size then mask is +// 1-extended. +if (match(Op1, m_PtrToInt(m_Specific(Op0 + return Op0; + +// NOTE: We may have attributes associated with the return value of the +// llvm.ptrmask intrinsic that will be lost when we just return the +// operand. We should try to preserve them. +if (match(Op1, m_AllOnes()) || Q.isUndefValue(Op1)) + return Op0; + +Constant *C; +if (match(Op1, m_ImmConstant(C))) { + KnownBits PtrKnown = computeKnownBits(Op0, /*Depth=*/0, Q); + // See if we only masking off bits we know are already zero due to + // alignment. + APInt IrrelivantPtrBits = nikic wrote: Irrelevant https://github.com/llvm/llvm-project/pull/67166 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [NFC] Remove Type::getInt8PtrTy (PR #71029)
nikic wrote: > Also adds AS = 0 as an optional argument to get() methods. I believe that was intentionally omitted to make sure address spaces aren't forgotten (getUnqual is used for the case where they aren't relevant). cc @arsenm Not sure whether this consideration is still relevant with opaque pointers, where we no longer create random pointer types for bitcasts all over the place. It may be better to accept the 0 default for simplicity. https://github.com/llvm/llvm-project/pull/71029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [WebAssembly] Mark externref as not being valid vector elements (PR #71069)
nikic wrote: @pmatos If you don't want to go all the way to target extension types, is it possible to gracefully handle this in wasm's TTI cost model? Return an invalid or very high cost in this case? https://github.com/llvm/llvm-project/pull/71069 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CodeGen] Emit `llvm.ptrmask` for `align_up` and `align_down` (PR #71238)
https://github.com/nikic approved this pull request. LGTM As a possible followup, we can probably drop the alignment assumption now? I don't think it adds additional value if we're using ptrmask... https://github.com/llvm/llvm-project/pull/71238 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [clang] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -0,0 +1,637 @@ +//===--- IRNormalizer.cpp - IR Normalizer ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// \file +/// This file implements the IRNormalizer class which aims to transform LLVM +/// Modules into a canonical form by reordering and renaming instructions while +/// preserving the same semantics. The normalizer makes it easier to spot +/// semantic differences while diffing two modules which have undergone +/// different passes. +/// +//===--===// + +#include "llvm/Transforms/Utils/IRNormalizer.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Transforms/Utils.h" +#include +#include + +#define DEBUG_TYPE "normalize" + +using namespace llvm; + +namespace { +/// IRNormalizer aims to transform LLVM IR into canonical form. +class IRNormalizer { +public: + /// \name Normalizer flags. + /// @{ + /// Preserves original order of instructions. + static cl::opt PreserveOrder; + /// Renames all instructions (including user-named). + static cl::opt RenameAll; + /// Folds all regular instructions (including pre-outputs). + static cl::opt FoldPreoutputs; + /// Sorts and reorders operands in commutative instructions. + static cl::opt ReorderOperands; + /// @} + + bool runOnFunction(Function &F); + +private: + // Random constant for hashing, so the state isn't zero. + const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL; + DenseSet NamedInstructions; + + /// \name Naming. + /// @{ + void nameFunctionArguments(Function &F); + void nameBasicBlocks(Function &F); + void nameInstruction(Instruction *I); + void nameAsInitialInstruction(Instruction *I); + void nameAsRegularInstruction(Instruction *I); + void foldInstructionName(Instruction *I); + /// @} + + /// \name Reordering. + /// @{ + void reorderInstructions(SmallVector &Outputs); + void reorderInstruction(Instruction *Used, Instruction *User, + SmallPtrSet &Visited); + void reorderInstructionOperandsByNames(Instruction *I); + void reorderPHIIncomingValues(PHINode *PN); + /// @} + + /// \name Utility methods. + /// @{ + SmallVector collectOutputInstructions(Function &F); + bool isOutput(const Instruction *I); + bool isInitialInstruction(const Instruction *I); + bool hasOnlyImmediateOperands(const Instruction *I); + SetVector + getOutputFootprint(Instruction *I, + SmallPtrSet &Visited); + /// @} +}; +} // namespace + +cl::opt IRNormalizer::PreserveOrder( +"preserve-order", cl::Hidden, +cl::desc("Preserves original instruction order")); +cl::opt IRNormalizer::RenameAll( +"rename-all", cl::Hidden, +cl::desc("Renames all instructions (including user-named)")); +cl::opt IRNormalizer::FoldPreoutputs( +"fold-all", cl::Hidden, +cl::desc("Folds all regular instructions (including pre-outputs)")); +cl::opt IRNormalizer::ReorderOperands( +"reorder-operands", cl::Hidden, +cl::desc("Sorts and reorders operands in commutative instructions")); + +/// Entry method to the IRNormalizer. +/// +/// \param M Module to normalize. +bool IRNormalizer::runOnFunction(Function &F) { + nameFunctionArguments(F); + nameBasicBlocks(F); + + SmallVector Outputs = collectOutputInstructions(F); + + if (!PreserveOrder) +reorderInstructions(Outputs); + + for (auto &I : Outputs) +nameInstruction(I); + + for (auto &I : instructions(F)) { +if (!PreserveOrder) { + if (ReorderOperands && I.isCommutative()) +reorderInstructionOperandsByNames(&I); + + if (auto *PN = dyn_cast(&I)) +reorderPHIIncomingValues(PN); +} + +foldInstructionName(&I); + } + + return true; +} + +/// Numbers arguments. +/// +/// \param F Function whose arguments will be renamed. +void IRNormalizer::nameFunctionArguments(Function &F) { + int ArgumentCounter = 0; + for (auto &A : F.args()) { +if (RenameAll || A.getName().empty()) { + A.setName("a" + Twine(ArgumentCounter)); + ++ArgumentCounter; +} + } +} + +/// Names basic blocks using a generated hash for each basic block in +/// a function considering the opcode and the order of output instructions. +/// +/// \param F Function containing basic blocks to rename. +void IRNormalizer::nameBasicBlocks(Function &F) { + for (auto &B : F) { +
[llvm] [clang] [clang-tools-extra] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -0,0 +1,637 @@ +//===--- IRNormalizer.cpp - IR Normalizer ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// \file +/// This file implements the IRNormalizer class which aims to transform LLVM +/// Modules into a canonical form by reordering and renaming instructions while +/// preserving the same semantics. The normalizer makes it easier to spot +/// semantic differences while diffing two modules which have undergone +/// different passes. +/// +//===--===// + +#include "llvm/Transforms/Utils/IRNormalizer.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Transforms/Utils.h" +#include +#include + +#define DEBUG_TYPE "normalize" + +using namespace llvm; + +namespace { +/// IRNormalizer aims to transform LLVM IR into canonical form. +class IRNormalizer { +public: + /// \name Normalizer flags. + /// @{ + /// Preserves original order of instructions. + static cl::opt PreserveOrder; + /// Renames all instructions (including user-named). + static cl::opt RenameAll; + /// Folds all regular instructions (including pre-outputs). + static cl::opt FoldPreoutputs; + /// Sorts and reorders operands in commutative instructions. + static cl::opt ReorderOperands; + /// @} + + bool runOnFunction(Function &F); + +private: + // Random constant for hashing, so the state isn't zero. + const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL; + DenseSet NamedInstructions; + + /// \name Naming. + /// @{ + void nameFunctionArguments(Function &F); + void nameBasicBlocks(Function &F); + void nameInstruction(Instruction *I); + void nameAsInitialInstruction(Instruction *I); + void nameAsRegularInstruction(Instruction *I); + void foldInstructionName(Instruction *I); + /// @} + + /// \name Reordering. + /// @{ + void reorderInstructions(SmallVector &Outputs); + void reorderInstruction(Instruction *Used, Instruction *User, + SmallPtrSet &Visited); + void reorderInstructionOperandsByNames(Instruction *I); + void reorderPHIIncomingValues(PHINode *PN); + /// @} + + /// \name Utility methods. + /// @{ + SmallVector collectOutputInstructions(Function &F); + bool isOutput(const Instruction *I); + bool isInitialInstruction(const Instruction *I); + bool hasOnlyImmediateOperands(const Instruction *I); + SetVector + getOutputFootprint(Instruction *I, + SmallPtrSet &Visited); + /// @} +}; +} // namespace + +cl::opt IRNormalizer::PreserveOrder( +"preserve-order", cl::Hidden, +cl::desc("Preserves original instruction order")); +cl::opt IRNormalizer::RenameAll( +"rename-all", cl::Hidden, +cl::desc("Renames all instructions (including user-named)")); +cl::opt IRNormalizer::FoldPreoutputs( +"fold-all", cl::Hidden, +cl::desc("Folds all regular instructions (including pre-outputs)")); +cl::opt IRNormalizer::ReorderOperands( +"reorder-operands", cl::Hidden, +cl::desc("Sorts and reorders operands in commutative instructions")); + +/// Entry method to the IRNormalizer. +/// +/// \param M Module to normalize. nikic wrote: This accepts F not M. https://github.com/llvm/llvm-project/pull/68176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -0,0 +1,637 @@ +//===--- IRNormalizer.cpp - IR Normalizer ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// \file +/// This file implements the IRNormalizer class which aims to transform LLVM +/// Modules into a canonical form by reordering and renaming instructions while +/// preserving the same semantics. The normalizer makes it easier to spot +/// semantic differences while diffing two modules which have undergone +/// different passes. +/// +//===--===// + +#include "llvm/Transforms/Utils/IRNormalizer.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Transforms/Utils.h" +#include +#include + +#define DEBUG_TYPE "normalize" + +using namespace llvm; + +namespace { +/// IRNormalizer aims to transform LLVM IR into canonical form. +class IRNormalizer { +public: + /// \name Normalizer flags. + /// @{ + /// Preserves original order of instructions. + static cl::opt PreserveOrder; + /// Renames all instructions (including user-named). + static cl::opt RenameAll; + /// Folds all regular instructions (including pre-outputs). + static cl::opt FoldPreoutputs; + /// Sorts and reorders operands in commutative instructions. + static cl::opt ReorderOperands; + /// @} + + bool runOnFunction(Function &F); + +private: + // Random constant for hashing, so the state isn't zero. + const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL; + DenseSet NamedInstructions; + + /// \name Naming. + /// @{ + void nameFunctionArguments(Function &F); + void nameBasicBlocks(Function &F); + void nameInstruction(Instruction *I); + void nameAsInitialInstruction(Instruction *I); + void nameAsRegularInstruction(Instruction *I); + void foldInstructionName(Instruction *I); + /// @} + + /// \name Reordering. + /// @{ + void reorderInstructions(SmallVector &Outputs); + void reorderInstruction(Instruction *Used, Instruction *User, + SmallPtrSet &Visited); + void reorderInstructionOperandsByNames(Instruction *I); + void reorderPHIIncomingValues(PHINode *PN); + /// @} + + /// \name Utility methods. + /// @{ + SmallVector collectOutputInstructions(Function &F); + bool isOutput(const Instruction *I); + bool isInitialInstruction(const Instruction *I); + bool hasOnlyImmediateOperands(const Instruction *I); + SetVector + getOutputFootprint(Instruction *I, + SmallPtrSet &Visited); + /// @} +}; +} // namespace + +cl::opt IRNormalizer::PreserveOrder( +"preserve-order", cl::Hidden, +cl::desc("Preserves original instruction order")); +cl::opt IRNormalizer::RenameAll( +"rename-all", cl::Hidden, +cl::desc("Renames all instructions (including user-named)")); +cl::opt IRNormalizer::FoldPreoutputs( +"fold-all", cl::Hidden, +cl::desc("Folds all regular instructions (including pre-outputs)")); +cl::opt IRNormalizer::ReorderOperands( +"reorder-operands", cl::Hidden, +cl::desc("Sorts and reorders operands in commutative instructions")); nikic wrote: Should probably prefix these option names? They're in the global namespace. https://github.com/llvm/llvm-project/pull/68176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [clang-tools-extra] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -543,6 +543,14 @@ variables with initializers are marked as internal. An interprocedural variant of :ref:`Sparse Conditional Constant Propagation `. +``ir-normalizer``: Transforms IR into a canonical form that's easier to diff nikic wrote: Looks like there are lots of leftovers of "canonical" vs "normalized". https://github.com/llvm/llvm-project/pull/68176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [LLVM] Add IRNormalizer Pass (PR #68176)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/68176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [clang-tools-extra] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -0,0 +1,637 @@ +//===--- IRNormalizer.cpp - IR Normalizer ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// \file +/// This file implements the IRNormalizer class which aims to transform LLVM +/// Modules into a canonical form by reordering and renaming instructions while +/// preserving the same semantics. The normalizer makes it easier to spot +/// semantic differences while diffing two modules which have undergone +/// different passes. +/// +//===--===// + +#include "llvm/Transforms/Utils/IRNormalizer.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Transforms/Utils.h" +#include +#include + +#define DEBUG_TYPE "normalize" + +using namespace llvm; + +namespace { +/// IRNormalizer aims to transform LLVM IR into canonical form. +class IRNormalizer { +public: + /// \name Normalizer flags. + /// @{ + /// Preserves original order of instructions. + static cl::opt PreserveOrder; + /// Renames all instructions (including user-named). + static cl::opt RenameAll; + /// Folds all regular instructions (including pre-outputs). + static cl::opt FoldPreoutputs; + /// Sorts and reorders operands in commutative instructions. + static cl::opt ReorderOperands; + /// @} + + bool runOnFunction(Function &F); + +private: + // Random constant for hashing, so the state isn't zero. + const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL; + DenseSet NamedInstructions; + + /// \name Naming. + /// @{ + void nameFunctionArguments(Function &F); + void nameBasicBlocks(Function &F); + void nameInstruction(Instruction *I); + void nameAsInitialInstruction(Instruction *I); + void nameAsRegularInstruction(Instruction *I); + void foldInstructionName(Instruction *I); + /// @} + + /// \name Reordering. + /// @{ + void reorderInstructions(SmallVector &Outputs); + void reorderInstruction(Instruction *Used, Instruction *User, + SmallPtrSet &Visited); + void reorderInstructionOperandsByNames(Instruction *I); + void reorderPHIIncomingValues(PHINode *PN); + /// @} + + /// \name Utility methods. + /// @{ + SmallVector collectOutputInstructions(Function &F); + bool isOutput(const Instruction *I); + bool isInitialInstruction(const Instruction *I); + bool hasOnlyImmediateOperands(const Instruction *I); + SetVector + getOutputFootprint(Instruction *I, + SmallPtrSet &Visited); + /// @} +}; +} // namespace + +cl::opt IRNormalizer::PreserveOrder( +"preserve-order", cl::Hidden, +cl::desc("Preserves original instruction order")); +cl::opt IRNormalizer::RenameAll( +"rename-all", cl::Hidden, +cl::desc("Renames all instructions (including user-named)")); +cl::opt IRNormalizer::FoldPreoutputs( +"fold-all", cl::Hidden, +cl::desc("Folds all regular instructions (including pre-outputs)")); +cl::opt IRNormalizer::ReorderOperands( +"reorder-operands", cl::Hidden, +cl::desc("Sorts and reorders operands in commutative instructions")); + +/// Entry method to the IRNormalizer. +/// +/// \param M Module to normalize. +bool IRNormalizer::runOnFunction(Function &F) { + nameFunctionArguments(F); + nameBasicBlocks(F); + + SmallVector Outputs = collectOutputInstructions(F); + + if (!PreserveOrder) +reorderInstructions(Outputs); + + for (auto &I : Outputs) +nameInstruction(I); + + for (auto &I : instructions(F)) { +if (!PreserveOrder) { + if (ReorderOperands && I.isCommutative()) +reorderInstructionOperandsByNames(&I); + + if (auto *PN = dyn_cast(&I)) +reorderPHIIncomingValues(PN); +} + +foldInstructionName(&I); + } + + return true; +} + +/// Numbers arguments. +/// +/// \param F Function whose arguments will be renamed. +void IRNormalizer::nameFunctionArguments(Function &F) { + int ArgumentCounter = 0; + for (auto &A : F.args()) { +if (RenameAll || A.getName().empty()) { + A.setName("a" + Twine(ArgumentCounter)); + ++ArgumentCounter; +} + } +} + +/// Names basic blocks using a generated hash for each basic block in +/// a function considering the opcode and the order of output instructions. +/// +/// \param F Function containing basic blocks to rename. +void IRNormalizer::nameBasicBlocks(Function &F) { + for (auto &B : F) { +
[clang] [llvm] [clang-tools-extra] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -0,0 +1,637 @@ +//===--- IRNormalizer.cpp - IR Normalizer ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// \file +/// This file implements the IRNormalizer class which aims to transform LLVM +/// Modules into a canonical form by reordering and renaming instructions while +/// preserving the same semantics. The normalizer makes it easier to spot +/// semantic differences while diffing two modules which have undergone +/// different passes. +/// +//===--===// + +#include "llvm/Transforms/Utils/IRNormalizer.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Transforms/Utils.h" +#include +#include + +#define DEBUG_TYPE "normalize" + +using namespace llvm; + +namespace { +/// IRNormalizer aims to transform LLVM IR into canonical form. +class IRNormalizer { +public: + /// \name Normalizer flags. + /// @{ + /// Preserves original order of instructions. + static cl::opt PreserveOrder; + /// Renames all instructions (including user-named). + static cl::opt RenameAll; + /// Folds all regular instructions (including pre-outputs). + static cl::opt FoldPreoutputs; + /// Sorts and reorders operands in commutative instructions. + static cl::opt ReorderOperands; + /// @} + + bool runOnFunction(Function &F); + +private: + // Random constant for hashing, so the state isn't zero. + const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL; + DenseSet NamedInstructions; + + /// \name Naming. + /// @{ + void nameFunctionArguments(Function &F); + void nameBasicBlocks(Function &F); + void nameInstruction(Instruction *I); + void nameAsInitialInstruction(Instruction *I); + void nameAsRegularInstruction(Instruction *I); + void foldInstructionName(Instruction *I); + /// @} + + /// \name Reordering. + /// @{ + void reorderInstructions(SmallVector &Outputs); + void reorderInstruction(Instruction *Used, Instruction *User, + SmallPtrSet &Visited); + void reorderInstructionOperandsByNames(Instruction *I); + void reorderPHIIncomingValues(PHINode *PN); + /// @} + + /// \name Utility methods. + /// @{ + SmallVector collectOutputInstructions(Function &F); + bool isOutput(const Instruction *I); + bool isInitialInstruction(const Instruction *I); + bool hasOnlyImmediateOperands(const Instruction *I); + SetVector + getOutputFootprint(Instruction *I, + SmallPtrSet &Visited); + /// @} +}; +} // namespace + +cl::opt IRNormalizer::PreserveOrder( +"preserve-order", cl::Hidden, +cl::desc("Preserves original instruction order")); +cl::opt IRNormalizer::RenameAll( +"rename-all", cl::Hidden, +cl::desc("Renames all instructions (including user-named)")); +cl::opt IRNormalizer::FoldPreoutputs( +"fold-all", cl::Hidden, +cl::desc("Folds all regular instructions (including pre-outputs)")); +cl::opt IRNormalizer::ReorderOperands( +"reorder-operands", cl::Hidden, +cl::desc("Sorts and reorders operands in commutative instructions")); + +/// Entry method to the IRNormalizer. +/// +/// \param M Module to normalize. +bool IRNormalizer::runOnFunction(Function &F) { + nameFunctionArguments(F); + nameBasicBlocks(F); + + SmallVector Outputs = collectOutputInstructions(F); + + if (!PreserveOrder) +reorderInstructions(Outputs); + + for (auto &I : Outputs) +nameInstruction(I); + + for (auto &I : instructions(F)) { +if (!PreserveOrder) { + if (ReorderOperands && I.isCommutative()) +reorderInstructionOperandsByNames(&I); + + if (auto *PN = dyn_cast(&I)) +reorderPHIIncomingValues(PN); +} + +foldInstructionName(&I); + } + + return true; +} + +/// Numbers arguments. +/// +/// \param F Function whose arguments will be renamed. +void IRNormalizer::nameFunctionArguments(Function &F) { + int ArgumentCounter = 0; + for (auto &A : F.args()) { +if (RenameAll || A.getName().empty()) { + A.setName("a" + Twine(ArgumentCounter)); + ++ArgumentCounter; +} + } +} + +/// Names basic blocks using a generated hash for each basic block in +/// a function considering the opcode and the order of output instructions. +/// +/// \param F Function containing basic blocks to rename. +void IRNormalizer::nameBasicBlocks(Function &F) { + for (auto &B : F) { +
[clang] [clang-tools-extra] [llvm] [LLVM] Add IRNormalizer Pass (PR #68176)
https://github.com/nikic commented: Could you please update the patch description with some information on what kind of normalization the pass does? It would also be great to post some examples, because I don't really get what kind of renaming and reordering this does just looking at the test coverage. One bit that's particularly non-obvious to me is why this normalization has to involve hashes? That seems like it would make things more unstable and hard to understand. I would recommend trying to run this pass (with all options enabled) over all existing tests to make sure that it doesn't cause any crashes/verifier failures. You're moving instructions around, and it's easy to get that wrong when invoke, callbr or catchswitch are involved. I would also try to add this pass at the end of the clang pipeline and run llvm-test-suite to verify that the normalization this does is indeed semantics-preserving. https://github.com/llvm/llvm-project/pull/68176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -0,0 +1,637 @@ +//===--- IRNormalizer.cpp - IR Normalizer ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// \file +/// This file implements the IRNormalizer class which aims to transform LLVM +/// Modules into a canonical form by reordering and renaming instructions while +/// preserving the same semantics. The normalizer makes it easier to spot +/// semantic differences while diffing two modules which have undergone +/// different passes. +/// +//===--===// + +#include "llvm/Transforms/Utils/IRNormalizer.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Transforms/Utils.h" +#include +#include + +#define DEBUG_TYPE "normalize" + +using namespace llvm; + +namespace { +/// IRNormalizer aims to transform LLVM IR into canonical form. +class IRNormalizer { +public: + /// \name Normalizer flags. + /// @{ + /// Preserves original order of instructions. + static cl::opt PreserveOrder; + /// Renames all instructions (including user-named). + static cl::opt RenameAll; + /// Folds all regular instructions (including pre-outputs). + static cl::opt FoldPreoutputs; + /// Sorts and reorders operands in commutative instructions. + static cl::opt ReorderOperands; + /// @} + + bool runOnFunction(Function &F); + +private: + // Random constant for hashing, so the state isn't zero. + const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL; + DenseSet NamedInstructions; + + /// \name Naming. + /// @{ + void nameFunctionArguments(Function &F); + void nameBasicBlocks(Function &F); + void nameInstruction(Instruction *I); + void nameAsInitialInstruction(Instruction *I); + void nameAsRegularInstruction(Instruction *I); + void foldInstructionName(Instruction *I); + /// @} + + /// \name Reordering. + /// @{ + void reorderInstructions(SmallVector &Outputs); + void reorderInstruction(Instruction *Used, Instruction *User, + SmallPtrSet &Visited); + void reorderInstructionOperandsByNames(Instruction *I); + void reorderPHIIncomingValues(PHINode *PN); + /// @} + + /// \name Utility methods. + /// @{ + SmallVector collectOutputInstructions(Function &F); + bool isOutput(const Instruction *I); + bool isInitialInstruction(const Instruction *I); + bool hasOnlyImmediateOperands(const Instruction *I); + SetVector + getOutputFootprint(Instruction *I, + SmallPtrSet &Visited); + /// @} +}; +} // namespace + +cl::opt IRNormalizer::PreserveOrder( +"preserve-order", cl::Hidden, +cl::desc("Preserves original instruction order")); +cl::opt IRNormalizer::RenameAll( +"rename-all", cl::Hidden, +cl::desc("Renames all instructions (including user-named)")); +cl::opt IRNormalizer::FoldPreoutputs( +"fold-all", cl::Hidden, +cl::desc("Folds all regular instructions (including pre-outputs)")); +cl::opt IRNormalizer::ReorderOperands( +"reorder-operands", cl::Hidden, +cl::desc("Sorts and reorders operands in commutative instructions")); + +/// Entry method to the IRNormalizer. +/// +/// \param M Module to normalize. +bool IRNormalizer::runOnFunction(Function &F) { + nameFunctionArguments(F); + nameBasicBlocks(F); + + SmallVector Outputs = collectOutputInstructions(F); + + if (!PreserveOrder) +reorderInstructions(Outputs); + + for (auto &I : Outputs) +nameInstruction(I); + + for (auto &I : instructions(F)) { +if (!PreserveOrder) { + if (ReorderOperands && I.isCommutative()) +reorderInstructionOperandsByNames(&I); + + if (auto *PN = dyn_cast(&I)) +reorderPHIIncomingValues(PN); +} + +foldInstructionName(&I); + } + + return true; +} + +/// Numbers arguments. +/// +/// \param F Function whose arguments will be renamed. +void IRNormalizer::nameFunctionArguments(Function &F) { + int ArgumentCounter = 0; + for (auto &A : F.args()) { +if (RenameAll || A.getName().empty()) { + A.setName("a" + Twine(ArgumentCounter)); + ++ArgumentCounter; +} + } +} + +/// Names basic blocks using a generated hash for each basic block in +/// a function considering the opcode and the order of output instructions. +/// +/// \param F Function containing basic blocks to rename. +void IRNormalizer::nameBasicBlocks(Function &F) { + for (auto &B : F) { +
[llvm] [clang-tools-extra] [clang] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -0,0 +1,637 @@ +//===--- IRNormalizer.cpp - IR Normalizer ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// \file +/// This file implements the IRNormalizer class which aims to transform LLVM +/// Modules into a canonical form by reordering and renaming instructions while +/// preserving the same semantics. The normalizer makes it easier to spot +/// semantic differences while diffing two modules which have undergone +/// different passes. +/// +//===--===// + +#include "llvm/Transforms/Utils/IRNormalizer.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Transforms/Utils.h" +#include +#include + +#define DEBUG_TYPE "normalize" + +using namespace llvm; + +namespace { +/// IRNormalizer aims to transform LLVM IR into canonical form. +class IRNormalizer { +public: + /// \name Normalizer flags. + /// @{ + /// Preserves original order of instructions. + static cl::opt PreserveOrder; + /// Renames all instructions (including user-named). + static cl::opt RenameAll; + /// Folds all regular instructions (including pre-outputs). + static cl::opt FoldPreoutputs; + /// Sorts and reorders operands in commutative instructions. + static cl::opt ReorderOperands; + /// @} + + bool runOnFunction(Function &F); + +private: + // Random constant for hashing, so the state isn't zero. + const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL; + DenseSet NamedInstructions; + + /// \name Naming. + /// @{ + void nameFunctionArguments(Function &F); + void nameBasicBlocks(Function &F); + void nameInstruction(Instruction *I); + void nameAsInitialInstruction(Instruction *I); + void nameAsRegularInstruction(Instruction *I); + void foldInstructionName(Instruction *I); + /// @} + + /// \name Reordering. + /// @{ + void reorderInstructions(SmallVector &Outputs); + void reorderInstruction(Instruction *Used, Instruction *User, + SmallPtrSet &Visited); + void reorderInstructionOperandsByNames(Instruction *I); + void reorderPHIIncomingValues(PHINode *PN); + /// @} + + /// \name Utility methods. + /// @{ + SmallVector collectOutputInstructions(Function &F); + bool isOutput(const Instruction *I); + bool isInitialInstruction(const Instruction *I); + bool hasOnlyImmediateOperands(const Instruction *I); + SetVector + getOutputFootprint(Instruction *I, + SmallPtrSet &Visited); + /// @} +}; +} // namespace + +cl::opt IRNormalizer::PreserveOrder( +"preserve-order", cl::Hidden, +cl::desc("Preserves original instruction order")); +cl::opt IRNormalizer::RenameAll( +"rename-all", cl::Hidden, +cl::desc("Renames all instructions (including user-named)")); +cl::opt IRNormalizer::FoldPreoutputs( +"fold-all", cl::Hidden, +cl::desc("Folds all regular instructions (including pre-outputs)")); +cl::opt IRNormalizer::ReorderOperands( +"reorder-operands", cl::Hidden, +cl::desc("Sorts and reorders operands in commutative instructions")); + +/// Entry method to the IRNormalizer. +/// +/// \param M Module to normalize. +bool IRNormalizer::runOnFunction(Function &F) { + nameFunctionArguments(F); + nameBasicBlocks(F); + + SmallVector Outputs = collectOutputInstructions(F); + + if (!PreserveOrder) +reorderInstructions(Outputs); + + for (auto &I : Outputs) +nameInstruction(I); + + for (auto &I : instructions(F)) { +if (!PreserveOrder) { + if (ReorderOperands && I.isCommutative()) +reorderInstructionOperandsByNames(&I); + + if (auto *PN = dyn_cast(&I)) +reorderPHIIncomingValues(PN); +} + +foldInstructionName(&I); + } + + return true; +} + +/// Numbers arguments. +/// +/// \param F Function whose arguments will be renamed. +void IRNormalizer::nameFunctionArguments(Function &F) { + int ArgumentCounter = 0; + for (auto &A : F.args()) { +if (RenameAll || A.getName().empty()) { + A.setName("a" + Twine(ArgumentCounter)); + ++ArgumentCounter; +} + } +} + +/// Names basic blocks using a generated hash for each basic block in +/// a function considering the opcode and the order of output instructions. +/// +/// \param F Function containing basic blocks to rename. +void IRNormalizer::nameBasicBlocks(Function &F) { + for (auto &B : F) { +
[clang-tools-extra] [clang] [llvm] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -0,0 +1,637 @@ +//===--- IRNormalizer.cpp - IR Normalizer ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// \file +/// This file implements the IRNormalizer class which aims to transform LLVM +/// Modules into a canonical form by reordering and renaming instructions while +/// preserving the same semantics. The normalizer makes it easier to spot +/// semantic differences while diffing two modules which have undergone +/// different passes. +/// +//===--===// + +#include "llvm/Transforms/Utils/IRNormalizer.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Transforms/Utils.h" +#include +#include + +#define DEBUG_TYPE "normalize" + +using namespace llvm; + +namespace { +/// IRNormalizer aims to transform LLVM IR into canonical form. +class IRNormalizer { +public: + /// \name Normalizer flags. + /// @{ + /// Preserves original order of instructions. + static cl::opt PreserveOrder; + /// Renames all instructions (including user-named). + static cl::opt RenameAll; + /// Folds all regular instructions (including pre-outputs). + static cl::opt FoldPreoutputs; + /// Sorts and reorders operands in commutative instructions. + static cl::opt ReorderOperands; + /// @} + + bool runOnFunction(Function &F); + +private: + // Random constant for hashing, so the state isn't zero. + const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL; + DenseSet NamedInstructions; + + /// \name Naming. + /// @{ + void nameFunctionArguments(Function &F); + void nameBasicBlocks(Function &F); + void nameInstruction(Instruction *I); + void nameAsInitialInstruction(Instruction *I); + void nameAsRegularInstruction(Instruction *I); + void foldInstructionName(Instruction *I); + /// @} + + /// \name Reordering. + /// @{ + void reorderInstructions(SmallVector &Outputs); + void reorderInstruction(Instruction *Used, Instruction *User, + SmallPtrSet &Visited); + void reorderInstructionOperandsByNames(Instruction *I); + void reorderPHIIncomingValues(PHINode *PN); + /// @} + + /// \name Utility methods. + /// @{ + SmallVector collectOutputInstructions(Function &F); + bool isOutput(const Instruction *I); + bool isInitialInstruction(const Instruction *I); + bool hasOnlyImmediateOperands(const Instruction *I); + SetVector + getOutputFootprint(Instruction *I, + SmallPtrSet &Visited); + /// @} +}; +} // namespace + +cl::opt IRNormalizer::PreserveOrder( +"preserve-order", cl::Hidden, +cl::desc("Preserves original instruction order")); +cl::opt IRNormalizer::RenameAll( +"rename-all", cl::Hidden, +cl::desc("Renames all instructions (including user-named)")); +cl::opt IRNormalizer::FoldPreoutputs( +"fold-all", cl::Hidden, +cl::desc("Folds all regular instructions (including pre-outputs)")); +cl::opt IRNormalizer::ReorderOperands( +"reorder-operands", cl::Hidden, +cl::desc("Sorts and reorders operands in commutative instructions")); + +/// Entry method to the IRNormalizer. +/// +/// \param M Module to normalize. +bool IRNormalizer::runOnFunction(Function &F) { + nameFunctionArguments(F); + nameBasicBlocks(F); + + SmallVector Outputs = collectOutputInstructions(F); + + if (!PreserveOrder) +reorderInstructions(Outputs); + + for (auto &I : Outputs) +nameInstruction(I); + + for (auto &I : instructions(F)) { +if (!PreserveOrder) { + if (ReorderOperands && I.isCommutative()) +reorderInstructionOperandsByNames(&I); + + if (auto *PN = dyn_cast(&I)) +reorderPHIIncomingValues(PN); +} + +foldInstructionName(&I); + } + + return true; +} + +/// Numbers arguments. +/// +/// \param F Function whose arguments will be renamed. +void IRNormalizer::nameFunctionArguments(Function &F) { + int ArgumentCounter = 0; + for (auto &A : F.args()) { +if (RenameAll || A.getName().empty()) { + A.setName("a" + Twine(ArgumentCounter)); + ++ArgumentCounter; +} + } +} + +/// Names basic blocks using a generated hash for each basic block in +/// a function considering the opcode and the order of output instructions. +/// +/// \param F Function containing basic blocks to rename. +void IRNormalizer::nameBasicBlocks(Function &F) { + for (auto &B : F) { +
[clang-tools-extra] [llvm] [clang] [LLVM] Add IRNormalizer Pass (PR #68176)
@@ -0,0 +1,637 @@ +//===--- IRNormalizer.cpp - IR Normalizer ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// \file +/// This file implements the IRNormalizer class which aims to transform LLVM +/// Modules into a canonical form by reordering and renaming instructions while +/// preserving the same semantics. The normalizer makes it easier to spot +/// semantic differences while diffing two modules which have undergone +/// different passes. +/// +//===--===// + +#include "llvm/Transforms/Utils/IRNormalizer.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Module.h" +#include "llvm/InitializePasses.h" +#include "llvm/Pass.h" +#include "llvm/PassRegistry.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Transforms/Utils.h" +#include +#include + +#define DEBUG_TYPE "normalize" + +using namespace llvm; + +namespace { +/// IRNormalizer aims to transform LLVM IR into canonical form. +class IRNormalizer { +public: + /// \name Normalizer flags. + /// @{ + /// Preserves original order of instructions. + static cl::opt PreserveOrder; + /// Renames all instructions (including user-named). + static cl::opt RenameAll; + /// Folds all regular instructions (including pre-outputs). + static cl::opt FoldPreoutputs; + /// Sorts and reorders operands in commutative instructions. + static cl::opt ReorderOperands; + /// @} + + bool runOnFunction(Function &F); + +private: + // Random constant for hashing, so the state isn't zero. + const uint64_t MagicHashConstant = 0x6acaa36bef8325c5ULL; + DenseSet NamedInstructions; + + /// \name Naming. + /// @{ + void nameFunctionArguments(Function &F); + void nameBasicBlocks(Function &F); + void nameInstruction(Instruction *I); + void nameAsInitialInstruction(Instruction *I); + void nameAsRegularInstruction(Instruction *I); + void foldInstructionName(Instruction *I); + /// @} + + /// \name Reordering. + /// @{ + void reorderInstructions(SmallVector &Outputs); + void reorderInstruction(Instruction *Used, Instruction *User, + SmallPtrSet &Visited); + void reorderInstructionOperandsByNames(Instruction *I); + void reorderPHIIncomingValues(PHINode *PN); + /// @} + + /// \name Utility methods. + /// @{ + SmallVector collectOutputInstructions(Function &F); + bool isOutput(const Instruction *I); + bool isInitialInstruction(const Instruction *I); + bool hasOnlyImmediateOperands(const Instruction *I); + SetVector + getOutputFootprint(Instruction *I, + SmallPtrSet &Visited); + /// @} +}; +} // namespace + +cl::opt IRNormalizer::PreserveOrder( +"preserve-order", cl::Hidden, +cl::desc("Preserves original instruction order")); +cl::opt IRNormalizer::RenameAll( +"rename-all", cl::Hidden, +cl::desc("Renames all instructions (including user-named)")); +cl::opt IRNormalizer::FoldPreoutputs( +"fold-all", cl::Hidden, +cl::desc("Folds all regular instructions (including pre-outputs)")); +cl::opt IRNormalizer::ReorderOperands( +"reorder-operands", cl::Hidden, +cl::desc("Sorts and reorders operands in commutative instructions")); + +/// Entry method to the IRNormalizer. +/// +/// \param M Module to normalize. +bool IRNormalizer::runOnFunction(Function &F) { + nameFunctionArguments(F); + nameBasicBlocks(F); + + SmallVector Outputs = collectOutputInstructions(F); + + if (!PreserveOrder) +reorderInstructions(Outputs); + + for (auto &I : Outputs) +nameInstruction(I); + + for (auto &I : instructions(F)) { +if (!PreserveOrder) { + if (ReorderOperands && I.isCommutative()) +reorderInstructionOperandsByNames(&I); + + if (auto *PN = dyn_cast(&I)) +reorderPHIIncomingValues(PN); +} + +foldInstructionName(&I); + } + + return true; +} + +/// Numbers arguments. +/// +/// \param F Function whose arguments will be renamed. +void IRNormalizer::nameFunctionArguments(Function &F) { + int ArgumentCounter = 0; + for (auto &A : F.args()) { +if (RenameAll || A.getName().empty()) { + A.setName("a" + Twine(ArgumentCounter)); + ++ArgumentCounter; +} + } +} + +/// Names basic blocks using a generated hash for each basic block in +/// a function considering the opcode and the order of output instructions. +/// +/// \param F Function containing basic blocks to rename. +void IRNormalizer::nameBasicBlocks(Function &F) { + for (auto &B : F) { +
[clang-tools-extra] [llvm] [clang] [LLVM] Add IRNormalizer Pass (PR #68176)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/68176 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][CodeGen] Stoping emitting alignment assumes for `align_{up,down}` (PR #71295)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/71295 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)
@@ -1577,7 +1577,7 @@ Value *PolynomialMultiplyRecognize::generate(BasicBlock::iterator At, static bool hasZeroSignBit(const Value *V) { if (const auto *CI = dyn_cast(V)) -return (CI->getType()->getSignBit() & CI->getSExtValue()) == 0; +return (CI->getIntegerType()->getSignBit() & CI->getSExtValue()) == 0; nikic wrote: ```suggestion return CI->getValue().isNonNegative(); ``` https://github.com/llvm/llvm-project/pull/75217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)
@@ -868,7 +868,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, } if (GVAlign > 1) { -unsigned DstWidth = CI2->getType()->getBitWidth(); +unsigned DstWidth = CI2->getIntegerType()->getBitWidth(); nikic wrote: ```suggestion unsigned DstWidth = CI2->getBitWidth(); ``` https://github.com/llvm/llvm-project/pull/75217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)
@@ -1062,7 +1062,7 @@ void PolynomialMultiplyRecognize::promoteTo(Instruction *In, // Promote immediates. for (unsigned i = 0, n = In->getNumOperands(); i != n; ++i) { if (ConstantInt *CI = dyn_cast(In->getOperand(i))) - if (CI->getType()->getBitWidth() < DestBW) + if (CI->getIntegerType()->getBitWidth() < DestBW) nikic wrote: ```suggestion if (CI->getBitWidth() < DestBW) ``` https://github.com/llvm/llvm-project/pull/75217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)
@@ -673,8 +673,8 @@ void ConstantHoistingPass::findBaseConstants(GlobalVariable *BaseGV) { llvm::stable_sort(ConstCandVec, [](const ConstantCandidate &LHS, const ConstantCandidate &RHS) { if (LHS.ConstInt->getType() != RHS.ConstInt->getType()) - return LHS.ConstInt->getType()->getBitWidth() < - RHS.ConstInt->getType()->getBitWidth(); + return LHS.ConstInt->getIntegerType()->getBitWidth() < + RHS.ConstInt->getIntegerType()->getBitWidth(); nikic wrote: ```suggestion return LHS.ConstInt->getBitWidth() < RHS.ConstInt->getBitWidth(); ``` https://github.com/llvm/llvm-project/pull/75217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)
@@ -1688,7 +1688,7 @@ void PolynomialMultiplyRecognize::setupPreSimplifier(Simplifier &S) { if (I->getOpcode() != Instruction::Or) return nullptr; ConstantInt *Msb = dyn_cast(I->getOperand(1)); - if (!Msb || Msb->getZExtValue() != Msb->getType()->getSignBit()) + if (!Msb || Msb->getZExtValue() != Msb->getIntegerType()->getSignBit()) nikic wrote: ```suggestion if (!Msb || !Msb->getValue().isSignMask()) ``` https://github.com/llvm/llvm-project/pull/75217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)
@@ -6079,7 +6079,7 @@ static Value *simplifyRelativeLoad(Constant *Ptr, Constant *Offset, Type *Int32Ty = Type::getInt32Ty(Ptr->getContext()); auto *OffsetConstInt = dyn_cast(Offset); - if (!OffsetConstInt || OffsetConstInt->getType()->getBitWidth() > 64) + if (!OffsetConstInt || OffsetConstInt->getIntegerType()->getBitWidth() > 64) nikic wrote: ```suggestion if (!OffsetConstInt || OffsetConstInt->getBitWidth() > 64) ``` https://github.com/llvm/llvm-project/pull/75217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)
nikic wrote: @eddyz87 Right, this is exactly the change I have been working on, see https://github.com/llvm/llvm-project/pull/75311. Unfortunately, it doesn't actually fix the BPF case, because that one involves a loop, and LVI is currently terrible at handling those. (Basically, even though the relevant condition is outside the loop, just querying something in the loop will form a cycle, which will be resolved to overdefined.) https://github.com/llvm/llvm-project/pull/73662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [LVI] Support using block values when handling conditions (PR #75311)
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/75311 >From 0b4f9e03bf84ffc0a24bc609879c96db9b1d2833 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 12 Dec 2023 15:55:29 +0100 Subject: [PATCH 1/2] [LVI] Support using block values when handling conditions Currently, LVI will only use conditions like "X < C" to constrain the value of X on the relevant edge. This patch extends it to handle conditions like "X < Y" by querying the known range of Y. This means that getValueFromCondition() and various related APIs can now return nullopt to indicate that they have pushed to the worklist, and need to be called again later. This behavior is currently controlled by a UseBlockValue option, and only enabled for actual edge value handling. All other places deriving constraints from conditions keep using the previous logic for now. --- llvm/lib/Analysis/LazyValueInfo.cpp | 155 -- .../cond-using-block-value.ll | 8 +- 2 files changed, 110 insertions(+), 53 deletions(-) diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 910f6b72afefe..88cf0dd2f36df 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -434,6 +434,28 @@ class LazyValueInfoImpl { void solve(); + // For the following methods, if UseBlockValue is true, the function may + // push additional values to the worklist and return nullopt. If + // UseBlockValue is false, it will never return nullopt. + + std::optional + getValueFromSimpleICmpCondition(CmpInst::Predicate Pred, Value *RHS, + const APInt &Offset, Instruction *CxtI, + bool UseBlockValue); + + std::optional + getValueFromICmpCondition(Value *Val, ICmpInst *ICI, bool isTrueDest, +bool UseBlockValue); + + std::optional + getValueFromCondition(Value *Val, Value *Cond, bool IsTrueDest, +bool UseBlockValue, unsigned Depth = 0); + + std::optional getEdgeValueLocal(Value *Val, + BasicBlock *BBFrom, + BasicBlock *BBTo, + bool UseBlockValue); + public: /// This is the query interface to determine the lattice value for the /// specified Value* at the context instruction (if specified) or at the @@ -755,14 +777,10 @@ LazyValueInfoImpl::solveBlockValuePHINode(PHINode *PN, BasicBlock *BB) { return Result; } -static ValueLatticeElement getValueFromCondition(Value *Val, Value *Cond, - bool isTrueDest = true, - unsigned Depth = 0); - // If we can determine a constraint on the value given conditions assumed by // the program, intersect those constraints with BBLV void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange( -Value *Val, ValueLatticeElement &BBLV, Instruction *BBI) { +Value *Val, ValueLatticeElement &BBLV, Instruction *BBI) { BBI = BBI ? BBI : dyn_cast(Val); if (!BBI) return; @@ -779,17 +797,21 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange( if (I->getParent() != BB || !isValidAssumeForContext(I, BBI)) continue; -BBLV = intersect(BBLV, getValueFromCondition(Val, I->getArgOperand(0))); +BBLV = intersect(BBLV, *getValueFromCondition(Val, I->getArgOperand(0), + /*IsTrueDest*/ true, + /*UseBlockValue*/ false)); } // If guards are not used in the module, don't spend time looking for them if (GuardDecl && !GuardDecl->use_empty() && BBI->getIterator() != BB->begin()) { -for (Instruction &I : make_range(std::next(BBI->getIterator().getReverse()), - BB->rend())) { +for (Instruction &I : + make_range(std::next(BBI->getIterator().getReverse()), BB->rend())) { Value *Cond = nullptr; if (match(&I, m_Intrinsic(m_Value(Cond -BBLV = intersect(BBLV, getValueFromCondition(Val, Cond)); +BBLV = intersect(BBLV, + *getValueFromCondition(Val, Cond, /*IsTrueDest*/ true, +/*UseBlockValue*/ false)); } } @@ -886,10 +908,14 @@ LazyValueInfoImpl::solveBlockValueSelect(SelectInst *SI, BasicBlock *BB) { // If the value is undef, a different value may be chosen in // the select condition. if (isGuaranteedNotToBeUndef(Cond, AC)) { -TrueVal = intersect(TrueVal, -getValueFromCondition(SI->getTrueValue(), Cond, true)); -FalseVal = intersect( -FalseVal, getValueFromCondition(SI->getFalseValue(), Cond, false)); +TrueVal = +intersect(TrueVal, *getValueFromCo
[llvm] [clang] [LVI] Support using block values when handling conditions (PR #75311)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/75311 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)
nikic wrote: > Most all the recommended changes assume the code paths will work equally well > for vector types as they do for scalar types. Can we be so sure this is the > case? This is why I opted to keep the casting assertions with the exception > of a few places where I could be sure the code path was clean. I don't think any of those code paths would cause a silent miscompile with vectors, which is the only thing we have to be concerned about (if it just hits a different assertion, that's fine). https://github.com/llvm/llvm-project/pull/75217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][fatlto] Don't set ThinLTO module flag with FatLTO (PR #75079)
https://github.com/nikic approved this pull request. LGTM -- I think this change is clearly right, independently of the ModuleID issue. https://github.com/llvm/llvm-project/pull/75079 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [IR] Fix GEP offset computations for vector GEPs (PR #75448)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/75448 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [IR] Fix GEP offset computations for vector GEPs (PR #75448)
@@ -108,7 +143,23 @@ class generic_gep_type_iterator { // that. bool isStruct() const { return isa(CurTy); } - bool isSequential() const { return isa(CurTy); } + bool isVector() const { return isa(CurTy); } + bool isSequential() const { return !isStruct(); } + + // For sequential GEP indices (all except those into structs), the index value + // can be translated into a byte offset by multiplying with an element stride. + // This function returns this stride, which both depends on the element type, + // and the containing aggregate type, as vectors always tightly bit-pack their + // elements. + TypeSize getSequentialElementStride(const DataLayout &DL) const { +assert(isSequential()); +Type *ElemTy = getIndexedType(); +TypeSize ElemSizeInBits = isVector() ? DL.getTypeSizeInBits(ElemTy) + : DL.getTypeAllocSizeInBits(ElemTy); +// Check for invalid GEPs that are not byte-addressable. +assert(ElemSizeInBits.isKnownMultipleOf(8)); +return ElemSizeInBits.divideCoefficientBy(8); nikic wrote: ```suggestion if (isVector()) { assert(DL.typeSizeEqualsStoreSize(ElemTy) && "Not byte-addressable"); return DL.getTypeStoreSize(ElemTy); } return DL.getTypeAllocSize(ElemTy); ``` Avoid explicit `8` constants. https://github.com/llvm/llvm-project/pull/75448 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [IR] Fix GEP offset computations for vector GEPs (PR #75448)
@@ -111,6 +111,20 @@ define void @test_evaluate_gep_as_ptrs_array(ptr addrspace(2) %B) { ret void } +define void @test_overaligned_vec(i8 %B) { +; This should be turned into a constexpr instead of being an instruction +; CHECK-LABEL: @test_overaligned_vec( +; TODO: In this test case, half is overaligned to 32 bits. +; Vectors are bit-packed and don't respect alignment. +; Thus, the byte offset of the second half in <2 x half> is 2 bytes, not 4 bytes: nikic wrote: Please do not interleave comments and CHECK lines. Move both comments outside the function. https://github.com/llvm/llvm-project/pull/75448 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [IR] Fix GEP offset computations for vector GEPs (PR #75448)
https://github.com/nikic commented: Looks fine to me. Alternative would be to forbid GEP indexing into vectors entirely. https://github.com/llvm/llvm-project/pull/75448 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [mlir] [llvm] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/75217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CGCUDANV] Unify PointerType members of CGNVCUDARuntime (NFC) (PR #75668)
https://github.com/nikic approved this pull request. LGTM There are already C-style function signatures in the comments, so I don't see value in keeping separate variable names. https://github.com/llvm/llvm-project/pull/75668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #75487)
nikic wrote: When building clang with clang, the regression on SemaChecking.cpp is now "only" 60% in terms of instructions retired (plus 0.4% during thin link, which is another ~50% in terms of SemaChecking). https://github.com/llvm/llvm-project/pull/75487 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits