[llvm-branch-commits] [llvm] 907a751 - [NFC][InstCombine] Add test for PR49778

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-05-03T16:41:30-07:00
New Revision: 907a751a38fff8d05b288ab52b19ba4e2cc1fc38

URL: 
https://github.com/llvm/llvm-project/commit/907a751a38fff8d05b288ab52b19ba4e2cc1fc38
DIFF: 
https://github.com/llvm/llvm-project/commit/907a751a38fff8d05b288ab52b19ba4e2cc1fc38.diff

LOG: [NFC][InstCombine] Add test for PR49778

(cherry picked from commit 5352490ce613f1bdedaf478765b089b1f0a8be0d)

Added: 

llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-pr49778.ll

Modified: 


Removed: 




diff  --git 
a/llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-pr49778.ll
 
b/llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-pr49778.ll
new file mode 100644
index 0..4865afa56a037
--- /dev/null
+++ 
b/llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-pr49778.ll
@@ -0,0 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; PR49778: this should not be folded to 0.
+define i32 @src(i1 %x2) {
+; CHECK-LABEL: @src(
+; CHECK-NEXT:ret i32 0
+;
+  %x13 = zext i1 %x2 to i32
+  %_7 = shl i32 4294967295, %x13
+  %mask = xor i32 %_7, 4294967295
+  %_8 = and i32 %mask, %x13
+  %_9 = shl i32 %_8, %x13
+  ret i32 %_9
+}



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 4a4b1c7 - [NFC][InstCombine] Extract canTryToConstantAddTwoShiftAmounts() as helper

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-05-03T16:41:31-07:00
New Revision: 4a4b1c75a1ea3f1ca90ef45470c42debb81ffc90

URL: 
https://github.com/llvm/llvm-project/commit/4a4b1c75a1ea3f1ca90ef45470c42debb81ffc90
DIFF: 
https://github.com/llvm/llvm-project/commit/4a4b1c75a1ea3f1ca90ef45470c42debb81ffc90.diff

LOG: [NFC][InstCombine] Extract canTryToConstantAddTwoShiftAmounts() as helper

(cherry picked from commit dceb3e599668496420d41b993100d23eeb7c0ada)

Added: 


Modified: 
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Removed: 




diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 7295369365c49..52f064e178206 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -21,6 +21,30 @@ using namespace PatternMatch;
 
 #define DEBUG_TYPE "instcombine"
 
+bool canTryToConstantAddTwoShiftAmounts(Value *Sh0, Value *ShAmt0, Value *Sh1,
+Value *ShAmt1) {
+  // We have two shift amounts from two 
diff erent shifts. The types of those
+  // shift amounts may not match. If that's the case let's bailout now..
+  if (ShAmt0->getType() != ShAmt1->getType())
+return false;
+
+  // As input, we have the following pattern:
+  //   Sh0 (Sh1 X, Q), K
+  // We want to rewrite that as:
+  //   Sh x, (Q+K)  iff (Q+K) u< bitwidth(x)
+  // While we know that originally (Q+K) would not overflow
+  // (because  2 * (N-1) u<= iN -1), we have looked past extensions of
+  // shift amounts. so it may now overflow in smaller bitwidth.
+  // To ensure that does not happen, we need to ensure that the total maximal
+  // shift amount is still representable in that smaller bit width.
+  unsigned MaximalPossibleTotalShiftAmount =
+  (Sh0->getType()->getScalarSizeInBits() - 1) +
+  (Sh1->getType()->getScalarSizeInBits() - 1);
+  APInt MaximalRepresentableShiftAmount =
+  APInt::getAllOnesValue(ShAmt0->getType()->getScalarSizeInBits());
+  return MaximalRepresentableShiftAmount.uge(MaximalPossibleTotalShiftAmount);
+}
+
 // Given pattern:
 //   (x shiftopcode Q) shiftopcode K
 // we should rewrite it as
@@ -57,26 +81,8 @@ Value 
*InstCombinerImpl::reassociateShiftAmtsOfTwoSameDirectionShifts(
   if (!match(Sh1, m_Shift(m_Value(X), m_ZExtOrSelf(m_Value(ShAmt1)
 return nullptr;
 
-  // We have two shift amounts from two 
diff erent shifts. The types of those
-  // shift amounts may not match. If that's the case let's bailout now..
-  if (ShAmt0->getType() != ShAmt1->getType())
-return nullptr;
-
-  // As input, we have the following pattern:
-  //   Sh0 (Sh1 X, Q), K
-  // We want to rewrite that as:
-  //   Sh x, (Q+K)  iff (Q+K) u< bitwidth(x)
-  // While we know that originally (Q+K) would not overflow
-  // (because  2 * (N-1) u<= iN -1), we have looked past extensions of
-  // shift amounts. so it may now overflow in smaller bitwidth.
-  // To ensure that does not happen, we need to ensure that the total maximal
-  // shift amount is still representable in that smaller bit width.
-  unsigned MaximalPossibleTotalShiftAmount =
-  (Sh0->getType()->getScalarSizeInBits() - 1) +
-  (Sh1->getType()->getScalarSizeInBits() - 1);
-  APInt MaximalRepresentableShiftAmount =
-  APInt::getAllOnesValue(ShAmt0->getType()->getScalarSizeInBits());
-  if (MaximalRepresentableShiftAmount.ult(MaximalPossibleTotalShiftAmount))
+  // Verify that it would be safe to try to add those two shift amounts.
+  if (!canTryToConstantAddTwoShiftAmounts(Sh0, ShAmt0, Sh1, ShAmt1))
 return nullptr;
 
   // We are only looking for signbit extraction if we have two right shifts.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] c27ad80 - [InstCombine] dropRedundantMaskingOfLeftShiftInput(): check that adding shift amounts doesn't overflow (PR49778)

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-05-03T16:41:31-07:00
New Revision: c27ad80507bfea35da07681fd4ec9972ca698015

URL: 
https://github.com/llvm/llvm-project/commit/c27ad80507bfea35da07681fd4ec9972ca698015
DIFF: 
https://github.com/llvm/llvm-project/commit/c27ad80507bfea35da07681fd4ec9972ca698015.diff

LOG: [InstCombine] dropRedundantMaskingOfLeftShiftInput(): check that adding 
shift amounts doesn't overflow (PR49778)

This is identical to 781d077afb0ed9771c513d064c40170c1ccd21c9,
but for the other function.

For certain shift amount bit widths, we must first ensure that adding
shift amounts is safe, that the sum won't have an unsigned overflow.

Fixes https://bugs.llvm.org/show_bug.cgi?id=49778

(cherry picked from commit 2760a808b9916a2839513b7fd7314a464f52481e)

Added: 


Modified: 
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-pr49778.ll

Removed: 




diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 52f064e17820..127bf8080959 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -226,9 +226,9 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator 
*OuterShift,
 // Peek through an optional zext of the shift amount.
 match(MaskShAmt, m_ZExtOrSelf(m_Value(MaskShAmt)));
 
-// We have two shift amounts from two 
diff erent shifts. The types of those
-// shift amounts may not match. If that's the case let's bailout now.
-if (MaskShAmt->getType() != ShiftShAmt->getType())
+// Verify that it would be safe to try to add those two shift amounts.
+if (!canTryToConstantAddTwoShiftAmounts(OuterShift, ShiftShAmt, Masked,
+MaskShAmt))
   return nullptr;
 
 // Can we simplify (MaskShAmt+ShiftShAmt) ?
@@ -258,9 +258,9 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator 
*OuterShift,
 // Peek through an optional zext of the shift amount.
 match(MaskShAmt, m_ZExtOrSelf(m_Value(MaskShAmt)));
 
-// We have two shift amounts from two 
diff erent shifts. The types of those
-// shift amounts may not match. If that's the case let's bailout now.
-if (MaskShAmt->getType() != ShiftShAmt->getType())
+// Verify that it would be safe to try to add those two shift amounts.
+if (!canTryToConstantAddTwoShiftAmounts(OuterShift, ShiftShAmt, Masked,
+MaskShAmt))
   return nullptr;
 
 // Can we simplify (ShiftShAmt-MaskShAmt) ?

diff  --git 
a/llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-pr49778.ll
 
b/llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-pr49778.ll
index 4865afa56a03..8d70733ed03d 100644
--- 
a/llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-pr49778.ll
+++ 
b/llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-pr49778.ll
@@ -4,7 +4,12 @@
 ; PR49778: this should not be folded to 0.
 define i32 @src(i1 %x2) {
 ; CHECK-LABEL: @src(
-; CHECK-NEXT:ret i32 0
+; CHECK-NEXT:[[X13:%.*]] = zext i1 [[X2:%.*]] to i32
+; CHECK-NEXT:[[_7:%.*]] = shl i32 -1, [[X13]]
+; CHECK-NEXT:[[MASK:%.*]] = xor i32 [[_7]], -1
+; CHECK-NEXT:[[_8:%.*]] = and i32 [[MASK]], [[X13]]
+; CHECK-NEXT:[[_9:%.*]] = shl i32 [[_8]], [[X13]]
+; CHECK-NEXT:ret i32 [[_9]]
 ;
   %x13 = zext i1 %x2 to i32
   %_7 = shl i32 4294967295, %x13



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 3568d61 - BPF: Implement TTI.IntImmCost() properly

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Yonghong Song
Date: 2021-05-03T16:48:10-07:00
New Revision: 3568d61f11e2eb0017c7b65707bee7bf4111c8ca

URL: 
https://github.com/llvm/llvm-project/commit/3568d61f11e2eb0017c7b65707bee7bf4111c8ca
DIFF: 
https://github.com/llvm/llvm-project/commit/3568d61f11e2eb0017c7b65707bee7bf4111c8ca.diff

LOG: BPF: Implement TTI.IntImmCost() properly

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 a260ae716030d5d2644a2af649501277d326bb21)

Added: 
llvm/lib/Target/BPF/BPFTargetTransformInfo.h

Modified: 
llvm/lib/Target/BPF/BPFTargetMachine.cpp
llvm/lib/Target/BPF/BPFTargetMachine.h

Removed: 




diff  --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp 
b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
index c0244b9f2c749..a8fef2517b03e 100644
--- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp
+++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
@@ -12,6 +12,7 @@
 
 #include "BPFTargetMachine.h"
 #include "BPF.h"
+#include "BPFTargetTransformInfo.h"
 #include "MCTargetDesc/BPFMCAsmInfo.h"
 #include "TargetInfo/BPFTargetInfo.h"
 #include "llvm/CodeGen/Passes.h"
@@ -145,6 +146,11 @@ void BPFPassConfig::addIRPasses() {
   TargetPassConfig::addIRPasses();
 }
 
+TargetTransformInfo
+BPFTargetMachine::getTargetTransformInfo(const Function &F) {
+  return TargetTransformInfo(BPFTTIImpl(this, F));
+}
+
 // Install an instruction selector pass using
 // the ISelDag to gen BPF code.
 bool BPFPassConfig::addInstSelector() {

diff  --git a/llvm/lib/Target/BPF/BPFTargetMachine.h 
b/llvm/lib/Target/BPF/BPFTargetMachine.h
index 5243a15eb7b05..61c8a44cc4024 100644
--- a/llvm/lib/Target/BPF/BPFTargetMachine.h
+++ b/llvm/lib/Target/BPF/BPFTargetMachine.h
@@ -34,6 +34,8 @@ class BPFTargetMachine : public LLVMTargetMachine {
 
   TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
 
+  TargetTransformInfo getTargetTransformInfo(const Function &F) override;
+
   TargetLoweringObjectFile *getObjFileLowering() const override {
 return TLOF.get();
   }

diff  --git a/llvm/lib/Target/BPF/BPFTargetTransformInfo.h 
b/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
new file mode 100644
index 0..622da9a0a3f7d
--- /dev/null
+++ b/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
@@ -0,0 +1,49 @@
+//===-- BPFTargetTransformInfo.h - BPF specific TTI -*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file uses the target's specific information to
+// provide more precise answers to certain TTI queries, while letting the
+// target independent and default TTI implementations handle the rest.
+//
+//===--===//
+
+#ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
+#define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
+
+#include "BPFTargetMachine.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/CodeGen/BasicTTIImpl.h"
+
+namespace llvm {
+class BPFTTIImpl : public BasicTTIImplBase {
+  typedef BasicTTIImplBase BaseT;
+  typedef TargetTransformInfo TTI;
+  friend BaseT;
+
+  const BPFSubtarget *ST;
+  const BPFTargetLowering *TLI;
+
+  const BPFSubtarget *getST() const { return ST; }
+  const BPFTargetLowering *getTLI() const { return TLI; }
+
+public:
+  explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F)
+  : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
+TLI(ST->getTargetLowering()) {}
+
+  int getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) {
+if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))
+  return TTI::TCC_Free;
+
+r

[llvm-branch-commits] [llvm] f9efff3 - BPF: Add LLVMAnalysis in CMakefile LINK_COMPONENTS

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Yonghong Song
Date: 2021-05-03T16:48:10-07:00
New Revision: f9efff398c1159b15964b166368b232f562e6cfc

URL: 
https://github.com/llvm/llvm-project/commit/f9efff398c1159b15964b166368b232f562e6cfc
DIFF: 
https://github.com/llvm/llvm-project/commit/f9efff398c1159b15964b166368b232f562e6cfc.diff

LOG: BPF: Add LLVMAnalysis in CMakefile LINK_COMPONENTS

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::~Model()':

Commit a260ae716030 ("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 74975d35b47631da0c7911561f16d3ffd1af142a)

Added: 


Modified: 
llvm/lib/Target/BPF/CMakeLists.txt

Removed: 




diff  --git a/llvm/lib/Target/BPF/CMakeLists.txt 
b/llvm/lib/Target/BPF/CMakeLists.txt
index 24c6c5e1255e..189a3a84c3df 100644
--- a/llvm/lib/Target/BPF/CMakeLists.txt
+++ b/llvm/lib/Target/BPF/CMakeLists.txt
@@ -35,6 +35,7 @@ add_llvm_target(BPFCodeGen
   BTFDebug.cpp
 
   LINK_COMPONENTS
+  Analysis
   AsmPrinter
   CodeGen
   Core



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 2460947 - BPF: Implement TTI.getCmpSelInstrCost() properly

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Yonghong Song
Date: 2021-05-03T16:48:11-07:00
New Revision: 2460947eefc2176693a4aa4d05cd9733e38c7ffe

URL: 
https://github.com/llvm/llvm-project/commit/2460947eefc2176693a4aa4d05cd9733e38c7ffe
DIFF: 
https://github.com/llvm/llvm-project/commit/2460947eefc2176693a4aa4d05cd9733e38c7ffe.diff

LOG: BPF: Implement TTI.getCmpSelInstrCost() properly

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 
  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 
  20:   b7 05 00 00 06 00 00 00 r5 = 6
  00a8 :
  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 1959ead525b8830cc8a345f45e1c3ef9902d3229)

Added: 


Modified: 
llvm/lib/Target/BPF/BPFTargetTransformInfo.h

Removed: 




diff  --git a/llvm/lib/Target/BPF/BPFTargetTransformInfo.h 
b/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
index 622da9a0a3f7..62055497e685 100644
--- a/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
+++ b/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
@@ -18,6 +18,7 @@
 #include "BPFTargetMachine.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/BasicTTIImpl.h"
+#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
 
 namespace llvm {
 class BPFTTIImpl : public BasicTTIImplBase {
@@ -42,6 +43,17 @@ class BPFTTIImpl : public BasicTTIImplBase {
 
 return TTI::TCC_Basic;
   }
+
+  int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
+ CmpInst::Predicate VecPred,
+ TTI::TargetCostKind CostKind,
+ const llvm::Instruction *I = nullptr) {
+if (Opcode == Instruction::Select)
+  return SCEVCheapExpansionBudget;
+
+return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
+ I);
+  }
 };
 
 } // end namespace llvm



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 6fe7c37 - BPF: Add LLVMTransformUtils in CMakefile LINK_COMPONENTS

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Yonghong Song
Date: 2021-05-03T16:48:11-07:00
New Revision: 6fe7c3728d1e98e05c67ceb03f429cb04a30e151

URL: 
https://github.com/llvm/llvm-project/commit/6fe7c3728d1e98e05c67ceb03f429cb04a30e151
DIFF: 
https://github.com/llvm/llvm-project/commit/6fe7c3728d1e98e05c67ceb03f429cb04a30e151.diff

LOG: BPF: Add LLVMTransformUtils in CMakefile LINK_COMPONENTS

Commit 1959ead525b8 ("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 6d102f15a3af0a44cf2e26677e260bee425312f3)

Added: 


Modified: 
llvm/lib/Target/BPF/CMakeLists.txt

Removed: 




diff  --git a/llvm/lib/Target/BPF/CMakeLists.txt 
b/llvm/lib/Target/BPF/CMakeLists.txt
index 189a3a84c3df..2d804ca8a73e 100644
--- a/llvm/lib/Target/BPF/CMakeLists.txt
+++ b/llvm/lib/Target/BPF/CMakeLists.txt
@@ -47,6 +47,7 @@ add_llvm_target(BPFCodeGen
   SelectionDAG
   Support
   Target
+  TransformUtils
 
   ADD_TO_COMPONENT
   BPF



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [polly] b8e4d4e - [PollyACC] Fix implicit function definitions. NFC.

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Michael Kruse
Date: 2021-05-03T17:18:07-07:00
New Revision: b8e4d4eafeded48f3c07797a2d8ccc950394085e

URL: 
https://github.com/llvm/llvm-project/commit/b8e4d4eafeded48f3c07797a2d8ccc950394085e
DIFF: 
https://github.com/llvm/llvm-project/commit/b8e4d4eafeded48f3c07797a2d8ccc950394085e.diff

LOG: [PollyACC] Fix implicit function definitions. NFC.

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 

This fixes llvm.org/PR50021

(cherry picked from commit 90e5ce0b0d6b0e72fdc034cbb612f67d67de0fdd)

Added: 


Modified: 
polly/lib/External/ppcg/print.c

Removed: 




diff  --git a/polly/lib/External/ppcg/print.c b/polly/lib/External/ppcg/print.c
index 79aaf2b00d237..dd839e48e51ba 100644
--- a/polly/lib/External/ppcg/print.c
+++ b/polly/lib/External/ppcg/print.c
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 
 #include "print.h"
 #include "util.h"



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [polly] 8b2c019 - [PollyACC] Fix declaration/stub definition mismatch. NFC.

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Michael Kruse
Date: 2021-05-03T17:18:08-07:00
New Revision: 8b2c019ace3c2e04108b550c5a2b60fc1c63865f

URL: 
https://github.com/llvm/llvm-project/commit/8b2c019ace3c2e04108b550c5a2b60fc1c63865f
DIFF: 
https://github.com/llvm/llvm-project/commit/8b2c019ace3c2e04108b550c5a2b60fc1c63865f.diff

LOG: [PollyACC] Fix declaration/stub definition mismatch. NFC.

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 89b59345ee29d2cc1afa1f60445916ae2e74be6d)

Added: 


Modified: 
polly/lib/External/ppcg/external.c

Removed: 




diff  --git a/polly/lib/External/ppcg/external.c 
b/polly/lib/External/ppcg/external.c
index 3a63ffbd97e55..c5ef6320e64fb 100644
--- a/polly/lib/External/ppcg/external.c
+++ b/polly/lib/External/ppcg/external.c
@@ -1,181 +1,192 @@
-#include "assert.h"
-#include "stdio.h"
-#include "stdlib.h"
+#include 
+#include 
+#include 
+#include 
+#include "cpu.h"
+#include "opencl.h"
+
 
 #define die() { \
   fprintf(stderr, "Dummy function %s called\n", __FUNCTION__); \
   abort(); \
 }
 
-void pet_scop_compute_outer_to_any(){
+__isl_give isl_union_map *pet_scop_compute_outer_to_any(
+  __isl_keep pet_scop *scop) {
   die();
 }
-void pet_scop_compute_outer_to_inner(){
+__isl_give isl_union_map *pet_scop_compute_outer_to_inner(
+  __isl_keep pet_scop *scop) {
   die();
 }
-void pet_tree_get_type(){
+enum pet_tree_type pet_tree_get_type(__isl_keep pet_tree *tree) {
   die();
 }
-void pet_tree_foreach_access_expr(){
+int pet_tree_foreach_access_expr(__isl_keep pet_tree *tree,
+  int (*fn)(__isl_keep pet_expr *expr, void *user), void *user) {
   die();
 }
-void pet_expr_get_ctx(){
+isl_ctx *pet_expr_get_ctx(__isl_keep pet_expr *expr) {
   die();
 }
-void pet_expr_access_is_read(){
+isl_bool pet_expr_access_is_read(__isl_keep pet_expr *expr) {
   die();
 }
-void pet_expr_access_is_write(){
+isl_bool pet_expr_access_is_write(__isl_keep pet_expr *expr) {
   die();
 }
-void pet_expr_access_get_tagged_may_read(){
+__isl_give isl_union_map *pet_expr_access_get_tagged_may_read(
+  __isl_keep pet_expr *expr) {
   die();
 }
-void pet_expr_access_get_tagged_may_write(){
+__isl_give isl_union_map *pet_expr_access_get_tagged_may_write(
+  __isl_keep pet_expr *expr) {
   die();
 }
-void pet_expr_access_get_must_write(){
+__isl_give isl_union_map *pet_expr_access_get_must_write(
+  __isl_keep pet_expr *expr) {
   die();
 }
-void pet_expr_access_get_index(){
+__isl_give isl_multi_pw_aff *pet_expr_access_get_index(
+  __isl_keep pet_expr *expr) {
   die();
 }
-void pet_expr_access_get_ref_id(){
+__isl_give isl_id *pet_expr_access_get_ref_id(__isl_keep pet_expr *expr) {
   die();
 }
-void print_cpu(){
+__isl_give isl_printer *print_cpu(__isl_take isl_printer *p,
+  struct ppcg_scop *ps, struct ppcg_options *options) {
   die();
 }
 
-void pet_stmt_print_body(){
-  die();
-}
-void pet_loc_get_start(){
-  die();
-}
-void pet_loc_get_end(){
-  die();
-}
-void pet_scop_collect_tagged_may_reads(){
-  die();
-}
-void pet_scop_collect_may_reads(){
+__isl_give isl_printer *pet_stmt_print_body(struct pet_stmt *stmt,
+  __isl_take isl_printer *p, __isl_keep isl_id_to_ast_expr *ref2expr) {
   die();
 }
-void pet_scop_collect_tagged_may_writes(){
+unsigned pet_loc_get_start(__isl_keep pet_loc *loc) {
   die();
 }
-void pet_scop_collect_may_writes(){
+unsigned pet_loc_get_end(__isl_keep pet_loc *loc) {
   die();
 }
-void pet_scop_collect_tagged_must_writes(){
+int pet_transform_C_source(isl_ctx *ctx, const char *input, FILE *output,
+  __isl_give isl_printer *(*transform)(__isl_take isl_printer *p,
+__isl_take pet_scop *scop, void *user), void *user) {
   die();
 }
-void pet_scop_collect_must_writes(){
+__isl_give isl_printer *pet_scop_print_original(__isl_keep pet_scop *scop,
+  __isl_take isl_printer *p) {
   die();
 }
-void pet_scop_collect_tagged_must_kills(){
+__isl_null pet_scop *pet_scop_free(__isl_take pet_scop *scop) {
   die();
 }
-void pet_transform_C_source(){
+__isl_give pet_scop *pet_scop_align_params(__isl_take pet_scop *scop) {
   die();
 }
-void pet_scop_print_original(){
+int pet_scop_can_build_ast_exprs(__isl_keep pet_scop *scop) {
   die();
 }
-void pet_scop_free(){
+int pet_scop_has_data_dependent_conditions(__isl_keep pet_scop *scop) {
   die();
 }
-void pet_scop_align_params(){
+int pet_tree_foreach_expr(__isl_keep pet_tree *tree,
+  int (*fn)(__isl_keep pet_expr

[llvm-branch-commits] [clang] 3263c81 - Partially Revert "scan-view: Remove Reporter.py and associated AppleScript files"

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Tom Stellard
Date: 2021-05-03T17:23:00-07:00
New Revision: 3263c81589eca689341ab5084723bdb7fe4a1286

URL: 
https://github.com/llvm/llvm-project/commit/3263c81589eca689341ab5084723bdb7fe4a1286
DIFF: 
https://github.com/llvm/llvm-project/commit/3263c81589eca689341ab5084723bdb7fe4a1286.diff

LOG: Partially Revert "scan-view: Remove Reporter.py and associated AppleScript 
files"

This reverts some of commit dbb01536f6f49fa428f170e34466072ef439b3e9.

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
dbb01536f6f49fa428f170e34466072ef439b3e9.

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D96367

(cherry picked from commit e3cd3a3c91524c957e06bb0170343548f02b6842)

Added: 
clang/tools/scan-view/share/Reporter.py

Modified: 
clang/tools/scan-view/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/scan-view/CMakeLists.txt 
b/clang/tools/scan-view/CMakeLists.txt
index dd3d33439299a..eccc6b83195b6 100644
--- a/clang/tools/scan-view/CMakeLists.txt
+++ b/clang/tools/scan-view/CMakeLists.txt
@@ -5,6 +5,7 @@ set(BinFiles
 
 set(ShareFiles
   ScanView.py
+  Reporter.py
   startfile.py
   bugcatcher.ico)
 

diff  --git a/clang/tools/scan-view/share/Reporter.py 
b/clang/tools/scan-view/share/Reporter.py
new file mode 100644
index 0..31a14fb0cf74e
--- /dev/null
+++ b/clang/tools/scan-view/share/Reporter.py
@@ -0,0 +1,183 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""Methods for reporting bugs."""
+
+import subprocess, sys, os
+
+__all__ = ['ReportFailure', 'BugReport', 'getReporters']
+
+#
+
+class ReportFailure(Exception):
+"""Generic exception for failures in bug reporting."""
+def __init__(self, value):
+self.value = value
+
+# Collect information about a bug.
+
+class BugReport(object):
+def __init__(self, title, description, files):
+self.title = title
+self.description = description
+self.files = files
+
+# Reporter interfaces.
+
+import os
+
+import email, mimetypes, smtplib
+from email import encoders
+from email.message import Message
+from email.mime.base import MIMEBase
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+
+#======#
+# ReporterParameter
+#======#
+
+class ReporterParameter(object):
+  def __init__(self, n):
+self.name = n
+  def getName(self):
+return self.name
+  def getValue(self,r,bugtype,getConfigOption):
+ return getConfigOption(r.getName(),self.getName())
+  def saveConfigValue(self):
+return True
+
+class TextParameter (ReporterParameter):
+  def getHTML(self,r,bugtype,getConfigOption):
+return """\
+
+%s:
+
+"""%(self.getName(),r.getName(),self.getName(),self.getValue(r,bugtype,getConfigOption))
+
+class SelectionParameter (ReporterParameter):
+  def __init__(self, n, values):
+ReporterParameter.__init__(self,n)
+self.values = values
+
+  def getHTML(self,r,bugtype,getConfigOption):
+default = self.getValue(r,bugtype,getConfigOption)
+return """\
+
+%s:
+%s
+"""%(self.getName(),r.getName(),self.getName(),'\n'.join(["""\
+%s"""%(o[0],
+ o[0] == default and ' 
selected="selected"' or '',
+ o[1]) for o in self.values]))
+
+#======#
+# Reporters
+#======#
+
+class EmailReporter(object):
+def getName(self):
+return 'Email'
+
+def getParameters(self):
+return [TextParameter(x) for x in ['To', 'From', 'SMTP Server', 'SMTP 
Port']]
+
+# Lifted from python email module examples.
+def attachFile(self, outer, path):
+# Guess the content type based on the file's extension.  Encoding
+# will be ignored, although we should check for simple things like
+# gzip'd or compressed files.
+ctype, encoding = mimetypes.guess_type(path)
+if ctype is None or encoding is not None:
+# No guess could be made, or the file is encoded (compressed), so
+# use a generic bag-of-bits type.
+ctype = 'application/octet-stream'
+maintype, subtype = ctype.split('/', 1)
+if maintype == 'text':
+fp = open(path)
+# Note: we should handle calculating the charset
+msg = MIMEText(fp.read(), _subtype=subtype)
+fp.close()
+else:
+fp = open(path, 'rb')
+msg = MIMEBase(maintype, subtype)
+msg.set_payload(fp.read())
+

[llvm-branch-commits] [llvm] c1831fc - [RISCV] Fix isel pattern of masked vmslt[u]

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: ShihPo Hung
Date: 2021-05-03T17:29:55-07:00
New Revision: c1831fc655979a0501a792f730d84d68e15a888e

URL: 
https://github.com/llvm/llvm-project/commit/c1831fc655979a0501a792f730d84d68e15a888e
DIFF: 
https://github.com/llvm/llvm-project/commit/c1831fc655979a0501a792f730d84d68e15a888e.diff

LOG: [RISCV] Fix isel pattern of masked vmslt[u]

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 fca5d63aa8d43a21557874d9bc040e944ab0500d)

Added: 


Modified: 
llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
llvm/test/CodeGen/RISCV/rvv/vmslt-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vmslt-rv64.ll
llvm/test/CodeGen/RISCV/rvv/vmsltu-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vmsltu-rv64.ll

Removed: 




diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td 
b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
index 60bd1b24cab85..5c228820f0cc8 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
@@ -3909,10 +3909,10 @@ foreach vti = AllIntegerVectors in {
(DecImm 
simm5_plus1:$rs2),
GPR:$vl,
vti.SEW)>;
-  def : Pat<(vti.Mask (int_riscv_vmslt_mask (vti.Mask V0),
+  def : Pat<(vti.Mask (int_riscv_vmslt_mask (vti.Mask VR:$merge),
 (vti.Vector vti.RegClass:$rs1),
 (vti.Scalar simm5_plus1:$rs2),
-(vti.Mask VR:$merge),
+(vti.Mask V0),
 (XLenVT (VLOp GPR:$vl,
 (!cast("PseudoVMSLE_VI_"#vti.LMul.MX#"_MASK")
   VR:$merge,
@@ -3922,17 +3922,17 @@ foreach vti = AllIntegerVectors in {
   GPR:$vl,
   vti.SEW)>;
 
- def : Pat<(vti.Mask (int_riscv_vmsltu (vti.Vector vti.RegClass:$rs1),
+  def : Pat<(vti.Mask (int_riscv_vmsltu (vti.Vector vti.RegClass:$rs1),
 (vti.Scalar simm5_plus1:$rs2),
 (XLenVT (VLOp GPR:$vl,
 (!cast("PseudoVMSLEU_VI_"#vti.LMul.MX) 
vti.RegClass:$rs1,
 (DecImm 
simm5_plus1:$rs2),
 GPR:$vl,
 vti.SEW)>;
-  def : Pat<(vti.Mask (int_riscv_vmsltu_mask (vti.Mask V0),
+  def : Pat<(vti.Mask (int_riscv_vmsltu_mask (vti.Mask VR:$merge),
  (vti.Vector vti.RegClass:$rs1),
  (vti.Scalar simm5_plus1:$rs2),
- (vti.Mask VR:$merge),
+ (vti.Mask V0),
  (XLenVT (VLOp GPR:$vl,
 (!cast("PseudoVMSLEU_VI_"#vti.LMul.MX#"_MASK")
   VR:$merge,
@@ -3950,11 +3950,11 @@ foreach vti = AllIntegerVectors in {

vti.RegClass:$rs1,
GPR:$vl,
vti.SEW)>;
-  def : Pat<(vti.Mask (int_riscv_vmsltu_mask (vti.Mask V0),
-(vti.Vector vti.RegClass:$rs1),
-(vti.Scalar 0),
-(vti.Mask VR:$merge),
-(XLenVT (VLOp GPR:$vl,
+  def : Pat<(vti.Mask (int_riscv_vmsltu_mask (vti.Mask VR:$merge),
+ (vti.Vector vti.RegClass:$rs1),
+ (vti.Scalar 0),
+ (vti.Mask V0),
+ (XLenVT (VLOp GPR:$vl,
 (!cast("PseudoVMSNE_VV_"#vti.LMul.MX#"_MASK")
  VR:$merge,
  vti.RegClass:$rs1,

diff  --git a/llvm/test/CodeGen/RISCV/rvv/vmslt-rv32.ll 
b/llvm/test/CodeGen/RISCV/rvv/vmslt-rv32.ll
index 894a232a167db..a51949573c979 100644
--- a/llvm/test/CodeGen/RISCV/rvv/vmslt-rv32.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/vmslt-rv32.ll
@@ -1504,9 +1504,

[llvm-branch-commits] [clang] e0fe1c5 - [OpenCL] Respect calling convention for builtin

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Luke Drummond
Date: 2021-05-03T17:32:26-07:00
New Revision: e0fe1c58acfa0bde36afde8354cb31fc1e0b75e2

URL: 
https://github.com/llvm/llvm-project/commit/e0fe1c58acfa0bde36afde8354cb31fc1e0b75e2
DIFF: 
https://github.com/llvm/llvm-project/commit/e0fe1c58acfa0bde36afde8354cb31fc1e0b75e2.diff

LOG: [OpenCL] Respect calling convention for builtin

`__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 fcfd3fda71905d7c48f75a531c2265ad3b9876ea)

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenOpenCL/sampler.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 31afbc6b42628..9c9bd4e374af7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6215,15 +6215,17 @@ llvm::SanitizerStatReport &CodeGenModule::getSanStats() 
{
 
   return *SanStats;
 }
+
 llvm::Value *
 CodeGenModule::createOpenCLIntToSamplerConversion(const Expr *E,
   CodeGenFunction &CGF) {
   llvm::Constant *C = ConstantEmitter(CGF).emitAbstract(E, E->getType());
-  auto SamplerT = getOpenCLRuntime().getSamplerType(E->getType().getTypePtr());
-  auto FTy = llvm::FunctionType::get(SamplerT, {C->getType()}, false);
-  return CGF.Builder.CreateCall(CreateRuntimeFunction(FTy,
-"__translate_sampler_initializer"),
-{C});
+  auto *SamplerT = 
getOpenCLRuntime().getSamplerType(E->getType().getTypePtr());
+  auto *FTy = llvm::FunctionType::get(SamplerT, {C->getType()}, false);
+  auto *Call = CGF.Builder.CreateCall(
+  CreateRuntimeFunction(FTy, "__translate_sampler_initializer"), {C});
+  Call->setCallingConv(Call->getCalledFunction()->getCallingConv());
+  return Call;
 }
 
 CharUnits CodeGenModule::getNaturalPointeeTypeAlignment(

diff  --git a/clang/test/CodeGenOpenCL/sampler.cl 
b/clang/test/CodeGenOpenCL/sampler.cl
index e6bda49f51c8d..5ad8d0dbbf376 100644
--- a/clang/test/CodeGenOpenCL/sampler.cl
+++ b/clang/test/CodeGenOpenCL/sampler.cl
@@ -39,7 +39,7 @@ kernel void foo(sampler_t smp_par) {
   // Case 2b
   sampler_t smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | 
CLK_FILTER_NEAREST;
   // CHECK: [[smp_ptr:%[A-Za-z0-9_\.]+]] = alloca %opencl.sampler_t 
addrspace(2)*
-  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 19)
+  // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 19)
   // CHECK: store %opencl.sampler_t addrspace(2)* [[SAMP]], %opencl.sampler_t 
addrspace(2)** [[smp_ptr]]
 
   // Case 1b
@@ -56,12 +56,12 @@ kernel void foo(sampler_t smp_par) {
 
   // Case 1a/2a
   fnc4smp(glb_smp);
-  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)
+  // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)
   // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* 
[[SAMP]])
 
   // Case 1a/2c
   fnc4smp(glb_smp_const);
-  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)
+  // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)
   // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* 
[[SAMP]])
 
   // Case 1c
@@ -70,12 +70,12 @@ kernel void foo(sampler_t smp_par) {
   // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* 
[[SAMP]])
 
   fnc4smp(5);
-  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 5)
+  // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 5)
   // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* 
[[SAMP]])
 
   const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
   fnc4smp(const_smp);
-   // CHECK: [[CONST_SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)
+   // CHECK: [[CO

[llvm-branch-commits] [llvm] a5a6cfe - BPF: permit type modifiers for __builtin_btf_type_id() relocation

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Yonghong Song
Date: 2021-05-03T17:37:51-07:00
New Revision: a5a6cfe2f030e81e689ed9af4e95ddf95c4d8675

URL: 
https://github.com/llvm/llvm-project/commit/a5a6cfe2f030e81e689ed9af4e95ddf95c4d8675
DIFF: 
https://github.com/llvm/llvm-project/commit/a5a6cfe2f030e81e689ed9af4e95ddf95c4d8675.diff

LOG: BPF: permit type modifiers for __builtin_btf_type_id() relocation

Lorenz Bauer from Cloudflare tried to use "const struct "
as the type for __builtin_btf_type_id(*(const struct )0, 1)
relocation and hit a llvm BPF fatal error.
   https://lore.kernel.org/bpf/a3782f71-3f6b-1e75-17a9-1827822c2...@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 ".
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 9c0274cdeae904089806be6faee72b9126d2cf5b)

Added: 
llvm/test/CodeGen/BPF/BTF/builtin-btf-type-id-2.ll

Modified: 
llvm/lib/Target/BPF/BPFPreserveDIType.cpp

Removed: 




diff  --git a/llvm/lib/Target/BPF/BPFPreserveDIType.cpp 
b/llvm/lib/Target/BPF/BPFPreserveDIType.cpp
index 18a4f60c171ae..0348e2200acbc 100644
--- a/llvm/lib/Target/BPF/BPFPreserveDIType.cpp
+++ b/llvm/lib/Target/BPF/BPFPreserveDIType.cpp
@@ -85,8 +85,17 @@ static bool BPFPreserveDITypeImpl(Function &F) {
 } else {
   Reloc = BPFCoreSharedInfo::BTF_TYPE_ID_REMOTE;
   DIType *Ty = cast(MD);
+  while (auto *DTy = dyn_cast(Ty)) {
+unsigned Tag = DTy->getTag();
+if (Tag != dwarf::DW_TAG_const_type &&
+Tag != dwarf::DW_TAG_volatile_type)
+  break;
+Ty = DTy->getBaseType();
+  }
+
   if (Ty->getName().empty())
 report_fatal_error("Empty type name for BTF_TYPE_ID_REMOTE reloc");
+  MD = Ty;
 }
 
 BasicBlock *BB = Call->getParent();

diff  --git a/llvm/test/CodeGen/BPF/BTF/builtin-btf-type-id-2.ll 
b/llvm/test/CodeGen/BPF/BTF/builtin-btf-type-id-2.ll
new file mode 100644
index 0..63c56c4dfec57
--- /dev/null
+++ b/llvm/test/CodeGen/BPF/BTF/builtin-btf-type-id-2.ll
@@ -0,0 +1,73 @@
+; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o %t1 %s
+; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s
+; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck 
-check-prefixes=CHECK %s
+; Source code:
+;   struct s {
+; int a;
+;   };
+;   int test(void) {
+; return __builtin_btf_type_id(*(const struct s *)0, 1);
+;   }
+; Compilation flag:
+;   clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c
+
+; Function Attrs: nounwind
+define dso_local i32 @test() #0 !dbg !7 {
+entry:
+  %0 = call i64 @llvm.bpf.btf.type.id(i32 0, i64 1), !dbg !11, 
!llvm.preserve.access.index !12
+  %conv = trunc i64 %0 to i32, !dbg !11
+  ret i32 %conv, !dbg !16
+}
+
+; CHECK: .long   1   # BTF_KIND_INT(id 
= 2)
+; CHECK-NEXT:.long   16777216# 0x100
+; CHECK-NEXT:.long   4
+; CHECK-NEXT:.long   16777248# 0x120
+
+; CHECK: .long   16  # 
BTF_KIND_STRUCT(id = 4)
+; CHECK-NEXT:.long   67108865# 0x401
+; CHECK-NEXT:.long   4
+; CHECK-NEXT:.long   18
+; CHECK-NEXT:.long   2
+
+; CHECK: .ascii  "int"   # string offset=1
+; CHECK: .ascii  ".text" # string offset=10
+; CHECK: .byte   115 # string offset=16
+; CHECK: .byte   97  # string offset=18
+; CHECK: .byte   48  # string offset=20
+
+; CHECK: .long   16  # FieldReloc
+; CHECK-NEXT:.long   10  # Field reloc 
section string offset=10
+; CHECK-NEXT:.long   1
+; CHECK-NEXT:.long   .Ltmp{{[0-9]+}}
+; CHECK-NEXT:.long   4
+; CHECK-NEXT:.long   20
+; CHECK-NEXT:.long   7
+
+; Function Attrs: nounwind readnone
+declare i64 @llvm.bpf.btf.type.id(i32, i64) #1
+
+attributes #0 = { nounwind "frame-pointer"="all" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
+attributes #1 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang 
version 13.0.0 (https://github.com/llvm/llvm-project.git 
9783e2098800b

[llvm-branch-commits] [llvm] 6564e0c - BPF: Fix a bug in peephole TRUNC elimination optimization

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Yonghong Song
Date: 2021-05-03T17:39:00-07:00
New Revision: 6564e0cf7e61518cb15443fca42bc2206a6123e2

URL: 
https://github.com/llvm/llvm-project/commit/6564e0cf7e61518cb15443fca42bc2206a6123e2
DIFF: 
https://github.com/llvm/llvm-project/commit/6564e0cf7e61518cb15443fca42bc2206a6123e2.diff

LOG: BPF: Fix a bug in peephole TRUNC elimination optimization

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 0x7fce54356bb0 __restore_rt
  #5 0x7fce4d51785e llvm::LiveVariables::HandleVirtRegUse(unsigned int,
  llvm::MachineBasicBlock*, llvm::MachineInstr&)
  #6 0x7fce4d519abe llvm::LiveVariables::runOnInstr(llvm::MachineInstr&,
  llvm::SmallVectorImpl&)
  #7 0x7fce4d519ec6 
llvm::LiveVariables::runOnBlock(llvm::MachineBasicBlock*, unsigned int)
  #8 0x7fce4d51a4bf 
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 51cdb780db3b9b46c783efcec672c4da272e9992)

Added: 
llvm/test/CodeGen/BPF/remove_truncate_8.ll

Modified: 
llvm/lib/Target/BPF/BPFMIPeephole.cpp

Removed: 




diff  --git a/llvm/lib/Target/BPF/BPFMIPeephole.cpp 
b/llvm/lib/Target/BPF/BPFMIPeephole.cpp
index df870314fffe3..354980e4bf3ce 100644
--- a/llvm/lib/Target/BPF/BPFMIPeephole.cpp
+++ b/llvm/lib/Target/BPF/BPFMIPeephole.cpp
@@ -475,6 +475,9 @@ bool BPFMIPeepholeTruncElim::eliminateTruncSeq(void) {
   if (MI.getOpcode() == BPF::SRL_ri &&
   MI.getOperand(2).getImm() == 32) {
 SrcReg = MI.getOperand(1).getReg();
+if (!MRI->hasOneNonDBGUse(SrcReg))
+  continue;
+
 MI2 = MRI->getVRegDef(SrcReg);
 DstReg = MI.getOperand(0).getReg();
 

diff  --git a/llvm/test/CodeGen/BPF/remove_truncate_8.ll 
b/llvm/test/CodeGen/BPF/remove_truncate_8.ll
new file mode 100644
index 0..fb1eabb0f0fd8
--- /dev/null
+++ b/llvm/test/CodeGen/BPF/remove_truncate_8.ll
@@ -0,0 +1,41 @@
+; RUN: llc < %s -march=bpf -verify-machineinstrs | FileCheck %s
+; Source Code:
+;   struct loc_prog {
+; unsigned int ip;
+; int len;
+;   };
+;   int exec_prog(struct loc_prog *prog) {
+; if (prog->ip < prog->len) {
+;   int x = prog->ip;
+;   if (x < 3)
+; prog->ip += 2;
+; }
+; return 3;
+;   }
+; Compilation flag:
+;   clang -target bpf -O2 -S -emit-llvm t.c
+
+%struct.loc_prog = type { i32, i32 }
+
+; Function Attrs: nofree norecurse nounwind willreturn
+define dso_local i32 @exec_prog(%struct.loc_prog* nocapture %prog) 
local_unnamed_addr {
+entry:
+  %ip = getelementptr inbounds %struct.loc_prog, %struct.loc_prog* %prog, i64 
0, i32 0
+  %0 = load i32, i32* %ip, align 4
+  %len = getelementptr inbounds %struct.loc_prog, %struct.loc_prog* %prog, i64 
0, i32 1
+  %1 = load i32, i32* %len, align 4
+  %cmp = icmp ult i32 %0, %1
+  %cmp2 = icmp slt i32 %0, 3
+  %or.cond = and i1 %cmp2, %cmp
+; CHECK: r{{[0-9]+}} <<= 32
+; CHECK: r{{[0-9]+}} s>>= 32
+  br i1 %or.cond, label %if.then3, label %if.end5
+
+if.then3: ; preds = %entry
+  %add = add nsw i32 %0, 2
+  store i32 %add, i32* %ip, align 4
+  br label %if.end5
+
+if.end5:  ; preds = %if.then3, %entry
+  ret i32 3
+}



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] e294ece - BPF: fix enum value 0 issue for __builtin_preserve_enum_value()

2021-05-03 Thread Tom Stellard via llvm-branch-commits

Author: Yonghong Song
Date: 2021-05-03T17:45:16-07:00
New Revision: e294ece42d85191875782ed05cb607451f493944

URL: 
https://github.com/llvm/llvm-project/commit/e294ece42d85191875782ed05cb607451f493944
DIFF: 
https://github.com/llvm/llvm-project/commit/e294ece42d85191875782ed05cb607451f493944.diff

LOG: BPF: fix enum value 0 issue for __builtin_preserve_enum_value()

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 283db5f0837d55f91242812003adf6e189ba743e)

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2d3d36f4adad0..2b55712d44c27 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2623,7 +2623,10 @@ static bool isValidBPFPreserveEnumValueArg(Expr *Arg) {
 return false;
 
   const auto *CE = dyn_cast(UO->getSubExpr());
-  if (!CE || CE->getCastKind() != CK_IntegralToPointer)
+  if (!CE)
+return false;
+  if (CE->getCastKind() != CK_IntegralToPointer &&
+  CE->getCastKind() != CK_NullToPointer)
 return false;
 
   // The integer must be from an EnumConstantDecl.

diff  --git a/clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c 
b/clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
index e07c680bb3702..b167b776e385e 100644
--- a/clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
+++ b/clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
@@ -4,10 +4,11 @@
 #define _(x, y) (__builtin_preserve_enum_value((x), (y)))
 
 enum AA {
+  VAL0 = 0,
   VAL1 = 2,
   VAL2 = 0x8000UL,
 };
-typedef enum { VAL10 = -2, VAL11 = 0x8000, }  __BB;
+typedef enum { VAL00, VAL10 = -2, VAL11 = 0x8000, }  __BB;
 
 unsigned unit1() {
   return _(*(enum AA *)VAL1, 0) + _(*(__BB *)VAL10, 1);
@@ -17,10 +18,16 @@ unsigned unit2() {
   return _(*(enum AA *)VAL2, 0) + _(*(__BB *)VAL11, 1);
 }
 
+unsigned unit3() {
+  return _(*(enum AA *)VAL0, 0) + _(*(__BB *)VAL00, 1);
+}
+
 // CHECK: @0 = private unnamed_addr constant [7 x i8] c"VAL1:2\00", align 1
 // CHECK: @1 = private unnamed_addr constant [9 x i8] c"VAL10:-2\00", align 1
 // CHECK: @2 = private unnamed_addr constant [17 x i8] c"VAL2:-2147483648\00", 
align 1
 // CHECK: @3 = private unnamed_addr constant [17 x i8] c"VAL11:4294934528\00", 
align 1
+// CHECK: @4 = private unnamed_addr constant [7 x i8] c"VAL0:0\00", align 1
+// CHECK: @5 = private unnamed_addr constant [8 x i8] c"VAL00:0\00", align 1
 
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 0, i8* getelementptr 
inbounds ([7 x i8], [7 x i8]* @0, i32 0, i32 0), i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[ENUM_AA:[0-9]+]]
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 1, i8* getelementptr 
inbounds ([9 x i8], [9 x i8]* @1, i32 0, i32 0), i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_ENUM:[0-9]+]]
@@ -28,5 +35,8 @@ unsigned unit2() {
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 2, i8* getelementptr 
inbounds ([17 x i8], [17 x i8]* @2, i32 0, i32 0), i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[ENUM_AA]]
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 3, i8* getelementptr 
inbounds ([17 x i8], [17 x i8]* @3, i32 0, i32 0), i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_ENUM]]
 
+// CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 4, i8* getelementptr 
inbounds ([7 x i8], [7 x i8]* @4, i32 0, i32 0), i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[ENUM_AA]]
+// CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 5, i8* getelementptr 
inbounds ([8 x i8], [8 x i8]* @5, i32 0, i32 0), i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_ENUM]]
+
 // CHECK: ![[ENUM_AA]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: 
"AA"
 // CHECK: ![[TYPEDEF_ENUM]] = !DIDerivedType(tag: DW_TAG_typedef, name: "__BB"



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits