1. Jun 04, 2021
  2. May 25, 2021
  3. May 20, 2021
    • Roman Lebedev's avatar
      ~(C + X) --> ~C - X (PR50308) · 4973ce53
      Roman Lebedev authored
      We can not rely on (C+X)-->(X+C) already happening,
      because we might not have visited that `add` yet.
      The added testcase would get stuck in an endless combine loop.
      
      (cherry-picked from 554b1bce)
      4973ce53
  4. May 18, 2021
    • Nick Desaulniers's avatar
      [LowerConstantIntrinsics] reuse isManifestLogic from ConstantFolding · de579bae
      Nick Desaulniers authored
      GlobalVariables are Constants, yet should not unconditionally be
      considered true for __builtin_constant_p.
      
      Via the LangRef
      https://llvm.org/docs/LangRef.html#llvm-is-constant-intrinsic:
      
          This intrinsic generates no code. If its argument is known to be a
          manifest compile-time constant value, then the intrinsic will be
          converted to a constant true value. Otherwise, it will be converted
          to a constant false value.
      
          In particular, note that if the argument is a constant expression
          which refers to a global (the address of which _is_ a constant, but
          not manifest during the compile), then the intrinsic evaluates to
          false.
      
      Move isManifestConstant from ConstantFolding to be a method of
      Constant so that we can reuse the same logic in
      LowerConstantIntrinsics.
      
      pr/41459
      
      Reviewed By: rsmith, george.burgess.iv
      
      Differential Revision: https://reviews.llvm.org/D102367
      
      (cherry picked from commit 8c72749b)
      de579bae
  5. May 13, 2021
  6. May 12, 2021
  7. May 11, 2021
  8. May 08, 2021
  9. May 07, 2021
    • Sanjay Patel's avatar
      [InstSimplify] fix potential miscompile in select value equivalence · 8e2ff387
      Sanjay Patel authored
      This is the sibling fix to c590a988 -
      as there, we can't subsitute a vector value the equality
      compare replacement that we are trying requires that the
      comparison is true for the entire value. Vector select
      can be partly true/false.
      
      (cherry picked from commit e2a0f512)
      8e2ff387
    • Sanjay Patel's avatar
      [InstSimplify] add test for vector select with operand replacement; NFC · 266c82f9
      Sanjay Patel authored
      We need a sibling fix to c590a988
      ( https://llvm.org/PR49832 ) to avoid miscompiling.
      
      (cherry picked from commit 78e5cf66)
      266c82f9
    • Sanjay Patel's avatar
      [InstCombine] fix potential miscompile in select value equivalence · 4a12f51a
      Sanjay Patel authored
      As shown in the example based on:
      https://llvm.org/PR49832
      ...and the existing test, we can't substitute
      a vector value because the equality compare
      replacement that we are attempting requires
      that the comparison is true for the entire
      value. Vector select can be partly true/false.
      
      (cherry picked from commit c590a988)
      4a12f51a
    • Sanjay Patel's avatar
      [InstCombine] add test for miscompile from select value equivalence; NFC · c89d5003
      Sanjay Patel authored
      The new test is reduced from:
      https://llvm.org/PR49832
      ...but we already show a potential miscompile in the existing test too.
      
      (cherry picked from commit c0b0da46)
      c89d5003
    • Ahsan Saghir's avatar
      [PowerPC] Prevent argument promotion of types with size greater than 128 bits · 225b7756
      Ahsan Saghir authored
      This patch prevents argument promotion of types having
      type size greater than 128 bits.
      
      Fixes Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=49952
      
      Reviewed By: #powerpc, nemanjai
      
      Differential Revision: https://reviews.llvm.org/D101188
      
      (cherry picked from commit 670736a9)
      225b7756
    • KAWASHIMA Takahiro's avatar
      [LoopReroll] Fix rerolling loop with extra instructions · ac593de1
      KAWASHIMA Takahiro authored
      Fixes PR47627
      
      This fix suppresses rerolling a loop which has an unrerollable
      instruction.
      
      Sample IR for the explanation below:
      
      ```
      define void @foo([2 x i32]* nocapture %a) {
      entry:
        br label %loop
      
      loop:
        ; base instruction
        %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %loop ]
      
        ; unrerollable instructions
        %stptrx = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 %indvar, i64 0
        store i32 999, i32* %stptrx, align 4
      
        ; extra simple arithmetic operations, used by root instructions
        %plus20 = add nuw nsw i64 %indvar, 20
        %plus10 = add nuw nsw i64 %indvar, 10
      
        ; root instruction 0
        %ldptr0 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 %plus20, i64 0
        %value0 = load i32, i32* %ldptr0, align 4
        %stptr0 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 %plus10, i64 0
        store i32 %value0, i32* %stptr0, align 4
      
        ; root instruction 1
        %ldptr1 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 %plus20, i64 1
        %value1 = load i32, i32* %ldptr1, align 4
        %stptr1 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 %plus10, i64 1
        store i32 %value1, i32* %stptr1, align 4
      
        ; loop-increment and latch
        %indvar.next = add nuw nsw i64 %indvar, 1
        %exitcond = icmp eq i64 %indvar.next, 5
        br i1 %exitcond, label %exit, label %loop
      
      exit:
        ret void
      }
      ```
      
      In the loop rerolling pass, `%indvar` and `%indvar.next` are appended
      to the `LoopIncs` vector in the `LoopReroll::DAGRootTracker::findRoots`
      function.
      
      Before this fix, two instructions with `unrerollable instructions`
      comment above are marked as `IL_All` at the end of the
      `LoopReroll::DAGRootTracker::collectUsedInstructions` function,
      as well as instructions with `extra simple arithmetic operations`
      comment and `loop-increment and latch` comment. It is incorrect
      because `IL_All` means that the instruction should be executed in all
      iterations of the rerolled loop but the `store` instruction should
      not.
      
      This fix rejects instructions which may have side effects and don't
      belong to def-use chains of any root instructions and reductions.
      
      See https://bugs.llvm.org/show_bug.cgi?id=47627 for more information.
      
      (cherry picked from commit d9a9c992)
      ac593de1
    • Tim Northover's avatar
      StackProtector: ensure protection does not interfere with tail call frame. · 471a386a
      Tim Northover authored
      The IR stack protector pass must insert stack checks before the call instead of
      between it and the return.
      
      Similarly, SDAG one should recognize that ADJCALLFRAME instructions could be
      part of the terminal sequence of a tail call. In this case because such call
      frames cannot be nested in LLVM the stack protection code must skip over the
      whole sequence (or risk clobbering argument registers).
      
      (cherry picked from commit 5e3d9fcc)
      471a386a
    • Brad Smith's avatar
      Fix typo, arvm7 -> armv7 · 6baa5ce2
      Brad Smith authored
      (cherry picked from commit 3a62d4fd)
      6baa5ce2
  10. May 04, 2021
    • Yonghong Song's avatar
      BPF: fix enum value 0 issue for __builtin_preserve_enum_value() · e294ece4
      Yonghong Song authored
      Lorenz Bauer reported that the following code will have
      compilation error for bpf target:
          enum e { TWO };
          bpf_core_enum_value_exists(enum e, TWO);
      The clang emitted the following error message:
          __builtin_preserve_enum_value argument 1 invalid
      
      In SemaChecking, an expression like "*(enum NAME)1" will have
      cast kind CK_IntegralToPointer, but "*(enum NAME)0" will have
      cast kind CK_NullToPointer. Current implementation only permits
      CK_IntegralToPointer, missing enum value 0 case.
      
      This patch permits CK_NullToPointer cast kind and
      the above test case can pass now.
      
      Differential Revision: https://reviews.llvm.org/D97659
      
      (cherry picked from commit 283db5f0)
      e294ece4
    • Yonghong Song's avatar
      BPF: Fix a bug in peephole TRUNC elimination optimization · 6564e0cf
      Yonghong Song authored
      Andrei Matei reported a llvm11 core dump for his bpf program
         https://bugs.llvm.org/show_bug.cgi?id=48578
      The core dump happens in LiveVariables analysis phase.
        #4 0x00007fce54356bb0 __restore_rt
        #5 0x00007fce4d51785e llvm::LiveVariables::HandleVirtRegUse(unsigned int,
            llvm::MachineBasicBlock*, llvm::MachineInstr&)
        #6 0x00007fce4d519abe llvm::LiveVariables::runOnInstr(llvm::MachineInstr&,
            llvm::SmallVectorImpl<unsigned int>&)
        #7 0x00007fce4d519ec6 llvm::LiveVariables::runOnBlock(llvm::MachineBasicBlock*, unsigned int)
        #8 0x00007fce4d51a4bf llvm::LiveVariables::runOnMachineFunction(llvm::MachineFunction&)
      The bug can be reproduced with llvm12 and latest trunk as well.
      
      Futher analysis shows that there is a bug in BPF peephole
      TRUNC elimination optimization, which tries to remove
      unnecessary TRUNC operations (a <<= 32; a >>= 32).
      Specifically, the compiler did wrong transformation for the
      following patterns:
         %1 = LDW ...
         %2 = SLL_ri %1, 32
         %3 = SRL_ri %2, 32
         ... %3 ...
         %4 = SRA_ri %2, 32
         ... %4 ...
      
      The current transformation did not check how many uses of %2
      and did transformation like
         %1 = LDW ...
         ... %1 ...
         %4 = SRL_ri %2, 32
         ... %4 ...
      and pseudo register %2 is used by not defined and
      caused LiveVariables analysis core dump.
      
      To fix the issue, when traversing back from SRL_ri to SLL_ri,
      check to ensure SLL_ri has only one use. Otherwise, don't
      do transformation.
      
      Differential Revision: https://reviews.llvm.org/D97792
      
      (cherry picked from commit 51cdb780)
      6564e0cf
    • Yonghong Song's avatar
      BPF: permit type modifiers for __builtin_btf_type_id() relocation · a5a6cfe2
      Yonghong Song authored
      Lorenz Bauer from Cloudflare tried to use "const struct <name>"
      as the type for __builtin_btf_type_id(*(const struct <name>)0, 1)
      relocation and hit a llvm BPF fatal error.
         https://lore.kernel.org/bpf/a3782f71-3f6b-1e75-17a9-1827822c2030@fb.com/
      
         ...
         fatal error: error in backend: Empty type name for BTF_TYPE_ID_REMOTE reloc
      
      Currently, we require the debuginfo type itself must have a name.
      In this case, the debuginfo type is "const" which points to "struct <name>".
      The "const" type does not have a name, hence the above fatal error
      will be triggered.
      
      Let us permit "const" and "volatile" type modifiers. We skip modifiers
      in some other cases as well like structure member type tracing.
      This can aviod the above fatal error.
      
      Differential Revision: https://reviews.llvm.org/D97986
      
      (cherry picked from commit 9c0274cd)
      a5a6cfe2
    • Luke Drummond's avatar
      [OpenCL] Respect calling convention for builtin · e0fe1c58
      Luke Drummond authored
      `__translate_sampler_initializer` has a calling convention of
      `spir_func`, but clang generated calls to it using the default CC.
      
      Instruction Combining was lowering these mismatching calling conventions
      to `store i1* undef` which itself was subsequently lowered to a trap
      instruction by simplifyCFG resulting in runtime `SIGILL`
      
      There are arguably two bugs here: but whether there's any wisdom in
      converting an obviously invalid call into a runtime crash over aborting
      with a sensible error message will require further discussion. So for
      now it's enough to set the right calling convention on the runtime
      helper.
      
      Reviewed By: svenh, bader
      
      Differential Revision: https://reviews.llvm.org/D98411
      
      (cherry picked from commit fcfd3fda)
      e0fe1c58
    • ShihPo Hung's avatar
      [RISCV] Fix isel pattern of masked vmslt[u] · c1831fc6
      ShihPo Hung authored
      This patch changes the operand order of masked vmslt[u]
      from (mask, rs1, scalar, maskedoff, vl)
      to (maskedoff, rs1, scalar, mask, vl).
      
      Reviewed By: craig.topper
      
      Differential Revision: https://reviews.llvm.org/D98839
      
      (cherry picked from commit fca5d63a)
      c1831fc6
    • Tom Stellard's avatar
      Partially Revert "scan-view: Remove Reporter.py and associated AppleScript files" · 3263c815
      Tom Stellard authored
      This reverts some of commit dbb01536.
      
      The Reporter module was still being used by the ScanView.py module and deleting
      it caused scan-view to fail.  This commit adds back Reporter.py but removes the
      code the references the AppleScript files which were removed in
      dbb01536.
      
      Reviewed By: NoQ
      
      Differential Revision: https://reviews.llvm.org/D96367
      
      (cherry picked from commit e3cd3a3c)
      3263c815
    • Michael Kruse's avatar
      [PollyACC] Fix declaration/stub definition mismatch. NFC. · 8b2c019a
      Michael Kruse authored
      external.c defines stub functions that are never used because of how
      Polly uses PPCG. Unfortunately, they are declared as functions without
      return values or parameters which does not match their declarations.
      Since they are never called, this was usually not a problem, but an LTO
      build gets confused with differently declared functions, or in case of
      pet_options_args, a global variable declaration that is defined as a
      function
      
      Resolve by including the declaring headers in external.c which forces
      the declaration and definition to match at compile-time.
      
      This fixes llvm.org/50021
      
      (cherry picked from commit 89b59345)
      8b2c019a
    • Michael Kruse's avatar
      [PollyACC] Fix implicit function definitions. NFC. · b8e4d4ea
      Michael Kruse authored
      The isl_id_* have been in used without including the correspodning
      isl/id.h header. According to rules in C, a function is defined
      implicitly when first used with an assumed int return type (32 bits on
      64 bit systems). But the implementation returns a pointer (64 bits on 64
      bit systems). Is usually has no consequence because the return value is
      stored in a registers that is 64 bits (RAX) and the optimizer does not
      truncate its value before using it again as a pointer value. However,
      LTO optimizers will be rightfull;y confused.
      
      Fix by including <isl/id.h>
      
      This fixes llvm.org/PR50021
      
      (cherry picked from commit 90e5ce0b)
      b8e4d4ea
    • Yonghong Song's avatar
      BPF: Add LLVMTransformUtils in CMakefile LINK_COMPONENTS · 6fe7c372
      Yonghong Song authored
      Commit 1959ead5 ("BPF: Implement TTI.getCmpSelInstrCost()
      properly") introduced a dependency on LLVMTransformUtils
      library. Let us encode this dependency explicitly in
      CMakefile to avoid build error.
      
      (cherry picked from commit 6d102f15)
      6fe7c372
    • Yonghong Song's avatar
      BPF: Implement TTI.getCmpSelInstrCost() properly · 2460947e
      Yonghong Song authored
      The Select insn in BPF is expensive as BPF backend
      needs to resolve with conditionals.  This patch set
      the getCmpSelInstrCost() to SCEVCheapExpansionBudget
      for Select insn to prevent some Select insn related
      optimizations.
      
      This change is motivated during bcc code review for
         https://github.com/iovisor/bcc/pull/3270
      where IndVarSimplifyPass eventually caused generating
      the following asm code:
        ;       for (i = 0; (i < VIRTIO_MAX_SGS) && (i < num); i++) {
            14:       16 05 40 00 00 00 00 00 if w5 == 0 goto +64 <LBB0_6>
            15:       bc 51 00 00 00 00 00 00 w1 = w5
            16:       04 01 00 00 ff ff ff ff w1 += -1
            17:       67 05 00 00 20 00 00 00 r5 <<= 32
            18:       77 05 00 00 20 00 00 00 r5 >>= 32
            19:       a6 01 01 00 05 00 00 00 if w1 < 5 goto +1 <LBB0_4>
            20:       b7 05 00 00 06 00 00 00 r5 = 6
        00000000000000a8 <LBB0_4>:
            21:       b7 02 00 00 00 00 00 00 r2 = 0
            22:       b7 01 00 00 00 00 00 00 r1 = 0
        ;       for (i = 0; (i < VIRTIO_MAX_SGS) && (i < num); i++) {
            23:       7b 1a e0 ff 00 00 00 00 *(u64 *)(r10 - 32) = r1
            24:       7b 5a c0 ff 00 00 00 00 *(u64 *)(r10 - 64) = r5
      Note that insn #15 has w1 = w5 and w1 is refined later but r5(w5) is
      eventually saved on stack at insn #24 for later use. This cause
      later verifier failures.
      
      With this change, IndVarSimplifyPass won't do the above
      transformation any more.
      
      Differential Revision: https://reviews.llvm.org/D97479
      
      (cherry picked from commit 1959ead5)
      2460947e
    • Yonghong Song's avatar
      BPF: Add LLVMAnalysis in CMakefile LINK_COMPONENTS · f9efff39
      Yonghong Song authored
      buildbot reported a build error like below:
        BPFTargetMachine.cpp:(.text._ZN4llvm19TargetTransformInfo5ModelINS_10BPFTTIImplEED2Ev
          [_ZN4llvm19TargetTransformInfo5ModelINS_10BPFTTIImplEED2Ev]+0x14):
          undefined reference to `llvm::TargetTransformInfo::Concept::~Concept()'
        lib/Target/BPF/CMakeFiles/LLVMBPFCodeGen.dir/BPFTargetMachine.cpp.o:
          In function `llvm::TargetTransformInfo::Model<llvm::BPFTTIImpl>::~Model()':
      
      Commit a260ae71 ("BPF: Implement TTI.IntImmCost() properly")
      added TargetTransformInfo to BPF, which requires LLVMAnalysis
      dependence. In certain cmake configurations, lacking explicit
      LLVMAnalysis dependency may cause compilation error.
      Similar to other targets, this patch added LLVMAnalysis
      in CMakefile LINK_COMPONENTS explicitly.
      
      (cherry picked from commit 74975d35)
      f9efff39
    • Yonghong Song's avatar
      BPF: Implement TTI.IntImmCost() properly · 3568d61f
      Yonghong Song authored
      This patch implemented TTI.IntImmCost() properly.
      Each BPF insn has 32bit immediate space, so for any immediate
      which can be represented as 32bit signed int, the cost
      is technically free. If an int cannot be presented as
      a 32bit signed int, a ld_imm64 instruction is needed
      and a TCC_Basic is returned.
      
      This change is motivated when we observed that
      several bpf selftests failed with latest llvm trunk, e.g.,
        #10/16 strobemeta.o:FAIL
        #10/17 strobemeta_nounroll1.o:FAIL
        #10/18 strobemeta_nounroll2.o:FAIL
        #10/19 strobemeta_subprogs.o:FAIL
        #96 snprintf_btf:FAIL
      
      The reason of the failure is due to that
      SpeculateAroundPHIsPass did aggressive transformation
      which alters control flow for which currently verifer
      cannot handle well. In llvm12, SpeculateAroundPHIsPass
      is not called.
      
      SpeculateAroundPHIsPass relied on TTI.getIntImmCost()
      and TTI.getIntImmCostInst() for profitability
      analysis. This patch implemented TTI.getIntImmCost()
      properly for BPF backend which also prevented
      transformation which caused the above test failures.
      
      Differential Revision: https://reviews.llvm.org/D96448
      
      (cherry picked from commit a260ae71)
      3568d61f