1. May 02, 2022
    • Balazs Benics's avatar
      [analyzer] Fix Static Analyzer g_memdup false-positive · 5a2e595e
      Balazs Benics authored
      `g_memdup()` allocates and copies memory, thus we should not assume that
      the returned memory region is uninitialized because it might not be the
      case.
      
      PS: It would be even better to copy the bindings to mimic the actual
      content of the buffer, but this works too.
      
      Fixes #53617
      
      Reviewed By: martong
      
      Differential Revision: https://reviews.llvm.org/D124436
      5a2e595e
    • Nikita Popov's avatar
      [ConstantFold] Don't convert getelementptr to ptrtoint+inttoptr · 597946a4
      Nikita Popov authored
      ConstantFolding currently converts "getelementptr i8, Ptr, (sub 0, V)"
      to "inttoptr (sub (ptrtoint Ptr), V)". This transform is, taken by
      itself, correct, but does came with two issues:
      
      1. It unnecessarily broadens provenance by introducing an inttoptr.
         We generally prefer not to introduce inttoptr during optimization.
      2. For the case where V == ptrtoint Ptr, this folds to inttoptr 0,
         which further folds to null. In that case provenance becomes
         incorrect. This has been observed as a real-world miscompile with
         rustc.
      
      We should probably address that incorrect inttoptr 0 fold at some
      point, but in either case we should also drop this inttoptr-introducing
      fold. Instead, replace it with a fold rooted at
      ptrtoint(getelementptr), which seems to cover the original
      motivation for this fold (test2 in the changed file).
      
      Differential Revision: https://reviews.llvm.org/D124677
      597946a4
    • David Green's avatar
    • Alex Zinenko's avatar
      [mlir] support isa/cast/dyn_cast<Operation *>(operation) · 946311b8
      Alex Zinenko authored
      This enables one to write generic code that can be instantiated for both
      specific operation classes and the common base class without
      specialization. Examples include functions that take/return ops, such
      as:
      
      ```mlir
      template <typename FnTy>
      void applyIf(FnTy &&lambda, ...) {
        for (Operation *op : ...) {
          auto specific = dyn_cast<function_traits<FnTy>::template arg_t<0>>(op);
          if (specific)
            lambda(specific);
        }
      }
      ```
      
      that would otherwise need to rely on template specialization to support
      lambdas that take specific operations and those that take `Operation *`.
      
      Reviewed By: rriddle
      
      Differential Revision: https://reviews.llvm.org/D124675
      946311b8
    • Phoebe Wang's avatar
      [ArgPromotion][Attributor] Update min-legal-vector-width when do promotion · 7c044542
      Phoebe Wang authored
      X86 codegen uses function attribute `min-legal-vector-width` to select the proper ABI. The intention of the attribute is to reflect user's requirement when they passing or returning vector arguments. So Clang front-end will iterate the vector arguments and set `min-legal-vector-width` to the width of the maximum for both caller and callee.
      
      It is assumed any middle end optimizations won't care of the attribute expect inlining and argument promotion.
      - For inlining, we will propagate the attribute of inlined functions because the inlining functions become the newer caller.
      - For argument promotion, we check the `min-legal-vector-width` of the caller and callee and refuse to promote when they don't match.
      
      The problem comes from the optimizations' combination, as shown by https://godbolt.org/z/zo3hba8xW. The caller `foo` has two callees `bar` and `baz`. When doing argument promotion, both `foo` and `bar` has the same `min-legal-vector-width`. So the argument was promoted to vector. Then the inlining inlines `baz` to `foo` and updates `min-legal-vector-width`, which results in ABI mismatch between `foo` and `bar`.
      
      This patch fixes the problem by expanding the concept of `min-legal-vector-width` to indicator of functions arguments. That says, any passes touch functions arguments have to set `min-legal-vector-width` to the value reflects the width of vector arguments. It makes sense to me because any arguments modifications are ABI related and should response for the ABI compatibility.
      
      Differential Revision: https://reviews.llvm.org/D123284
      7c044542
    • Shraiysh Vaishay's avatar
      [flang] Added tests for taskwait and taskyield translation · e6295c64
      Shraiysh Vaishay authored
      Reviewed By: kiranchandramohan
      
      Differential Revision: https://reviews.llvm.org/D124229
      
      
      
      Co-authored-by: default avatarSourabh Singh Tomar <SourabhSingh.Tomar@amd.com>
      e6295c64
    • Congzhe Cao's avatar
      [LoopCacheAnalysis] Use stable_sort() to avoid non-deterministic print output · 3d6fe7ac
      Congzhe Cao authored
      The print output of loop cache analysis sometimes has a non-deterministic order
      and therefore we have been using `CHECK-DAG` in its lit tests. This patch changes
      the sorting of LoopCosts to llvm::stable_sort() where we compare loop cost numbers
      and sort the loops. In case of the same loop cost numbers, llvm::stable_sort() now
      would output a deterministic loop order.
      
      Reviewed By: Meinersbur, fhahn, #loopoptwg
      
      Differential Revision: https://reviews.llvm.org/D124725
      3d6fe7ac
    • Ben Shi's avatar
      [clang][preprocessor] Add more macros to target AVR · 42fa5bae
      Ben Shi authored
      Reviewed By: MaskRay, aykevl
      
      Differential Revision: https://reviews.llvm.org/D124157
      42fa5bae
    • Brad Smith's avatar
      [Driver][Ananas] -r: imply -nostdlib like GCC · a132e527
      Brad Smith authored
      Similar to D116843 for Gnu.cpp
      
      Reviewed By: zhmu, MaskRay
      
      Differential Revision: https://reviews.llvm.org/D124729
      a132e527
    • Fangrui Song's avatar
      6cfcfbdc
    • Ben Shi's avatar
      [compiler-rt][builtins] Add several helper functions for AVR · fb7a4354
      Ben Shi authored
      __mulqi3 : int8 multiplication
      __mulhi3 : int16 multiplication
         _exit : golobal terminator
      
      Reviewed By: MaskRay, aykevl
      
      Differential Revision: https://reviews.llvm.org/D123200
      fb7a4354
    • LLVM GN Syncbot's avatar
      [gn build] Port 3939e99a · 1790e297
      LLVM GN Syncbot authored
      1790e297
    • Matt Arsenault's avatar
      llvm-reduce: Fix not removing first instruction in MachineBasicBlock · aabea3b2
      Matt Arsenault authored
      This had the surprising behavior of using whatever instruction
      happened to be first in the block as an anchor point to stick random
      implicit defs on. Use a real implicit_def instead.
      aabea3b2
    • Matt Arsenault's avatar
      llvm-reduce: Introduce new scoring mechanism for MIR reductions · 35264e71
      Matt Arsenault authored
      Many MIR reductions benefit from or require increasing the instruction
      count. For example, unlike in the IR, you may need to insert a new
      instruction to represent an undef. The current instruction reduction
      pass works around this by sticking implicit defs on whatever
      instruction happens to be first in the entry block block.
      
      Other strategies I've applied manually include breaking instructions
      with multiple defs into separate instructions, or breaking large
      register defs into multiple subregister defs.
      
      Make up a simple scoring system based on what I generally try to get
      rid of first when manually reducing. Counts implicit defs as free
      since reduction passes will be introducing them, although they
      probably should count for something. It also might make more sense to
      have a comparison the two functions, rather than having to compute a
      contextless number. This isn't particularly well tested since overall
      the MIR support isn't in a place where it is useful on the kinds of
      testcases I want to throw at it.
      35264e71
    • Matt Arsenault's avatar
      llvm-reduce: Do not try to delete frame instructions · 0b896b75
      Matt Arsenault authored
      The verifier enforces these appearing as balanced pairs, so just
      deleting one has no real chance of producing something valid.
      0b896b75
    • Matt Arsenault's avatar
      llvm-reduce: Add pass to reduce IR references from MIR · 3939e99a
      Matt Arsenault authored
      This is typically the first thing I do when reducing a new testcase
      until the IR section can be deleted.
      3939e99a
    • Fangrui Song's avatar
    • Sylvestre Ledru's avatar
      doc: update of the adv build doc now that clang is in tree too · ee4ac3a8
      Sylvestre Ledru authored
      And be more consistent in the declarations
      ee4ac3a8
    • River Riddle's avatar
      [mlir:PDLInterp] Refactor the implementation of result type inferrence · 3c752289
      River Riddle authored
      The current implementation uses a discrete "pdl_interp.inferred_types"
      operation, which acts as a "fake" handle to a type range. This op is
      used as a signal to pdl_interp.create_operation that types should be
      inferred. This is terribly awkward and clunky though:
      
      * This op doesn't have a byte code representation, and its conversion
        to bytecode kind of assumes that it is only used in a certain way. The
        current lowering is also broken and seemingly untested.
      
      * Given that this is a different operation, it gives off the assumption
        that it can be used multiple times, or that after the first use
        the value contains the inferred types. This isn't the case though,
        the resultant type range can never actually be used as a type range.
      
      This commit refactors the representation by removing the discrete
      InferredTypesOp, and instead adds a UnitAttr to
      pdl_interp.CreateOperation that signals when the created operations
      should infer their types. This leads to a much much cleaner abstraction,
      a more optimal bytecode lowering, and also allows for better error
      handling and diagnostics when a created operation doesn't actually
      support type inferrence.
      
      Differential Revision: https://reviews.llvm.org/D124587
      3c752289
    • Florian Hahn's avatar
      [SimpleLoopUnswitch] Freeze individual OR/AND operands. · 5387a38c
      Florian Hahn authored
      In some cases, it is not enough to freeze the final AND/OR operation
      when chaining a number of invariant conditions together.
      
      After creating a chain of ANDs/ORs, we assume all unswitched operands to
      be either true or false. But if any of the operands is poison, the rest
      of the operands could have any value after branching on the frozen
      condition.
      
      To avoid that, freeze individual operands, if needed. In some cases this
      may lead to unnecessary freezes, but it seems required at least for some
      cases (see trivial-unswitch-freeze-individual-conditions.ll)
      
      Reviewed By: nikic
      
      Differential Revision: https://reviews.llvm.org/D124554
      5387a38c
    • Simon Pilgrim's avatar
      [VectorCombine] Merge isa<>/cast<> into dyn_cast<>. NFC. · 34f97a37
      Simon Pilgrim authored
      We want to handle the the assert in VectorCombine so avoid the repeated isa/cast code.
      34f97a37
    • Michael Kruse's avatar
      [Polly] Fix test after D119669. · 809ca66e
      Michael Kruse authored
      809ca66e
    • Simon Pilgrim's avatar
    • Stanislav Gatev's avatar
      [clang][dataflow] Optimize flow condition representation · 955a05a2
      Stanislav Gatev authored
      Enable efficient implementation of context-aware joining of distinct
      boolean values. It can be used to join distinct boolean values while
      preserving flow condition information.
      
      Flow conditions are represented as Token <=> Clause iff formulas. To
      perform context-aware joining, one can simply add the tokens of flow
      conditions to the formula when joining distinct boolean values, e.g:
      `makeOr(makeAnd(FC1, Val1), makeAnd(FC2, Val2))`. This significantly
      simplifies the implementation of `Environment::join`.
      
      This patch removes the `DataflowAnalysisContext::getSolver` method.
      The `DataflowAnalysisContext::flowConditionImplies` method should be
      used instead.
      
      Reviewed-by: ymandel, xazax.hun
      
      Differential Revision: https://reviews.llvm.org/D124395
      955a05a2
    • Simon Pilgrim's avatar
      980f41d7
    • Simon Pilgrim's avatar
      d4f06ec8
  2. May 01, 2022