[llvm-branch-commits] [llvm] f5f7ff8 - [dsymutil][DWARFLinker][NFC] Refactor usages of UniquingStringPool.

2021-01-03 Thread Alexey Lapshin via llvm-branch-commits

Author: Alexey Lapshin
Date: 2021-01-03T14:44:51+03:00
New Revision: f5f7ff8d0faacf4813e38081e551b9ab6cdc76ae

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

LOG: [dsymutil][DWARFLinker][NFC] Refactor usages of UniquingStringPool.

That refactoring is helpful since it reduces data inter-dependencies.
Which is good for current implementation and even more good for
fully multi-thread implementation. The idea of the refactoring
is to delete UniquingStringPool from the global DWARFLinker level.
It is used to unique type names while ODR deduplication is done.
Thus we move UniquingStringPool into the DeclContextTree which
matched to UniquingStringPool usage scope.

golden-dsymutil/dsymutil 23787992
clang MD5: 7d9873ff94f0246b6ab1ec3e8d0f3f06

build-Release/bin/dsymutil 23921272
clang MD5: 7d9873ff94f0246b6ab1ec3e8d0f3f06

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

Added: 


Modified: 
llvm/include/llvm/DWARFLinker/DWARFLinker.h
llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h
llvm/include/llvm/DWARFLinker/DWARFLinkerDeclContext.h
llvm/lib/DWARFLinker/DWARFLinker.cpp
llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp

Removed: 




diff  --git a/llvm/include/llvm/DWARFLinker/DWARFLinker.h 
b/llvm/include/llvm/DWARFLinker/DWARFLinker.h
index edf74168d5b3..97faad6b6180 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/DWARFLinker.h
@@ -467,7 +467,6 @@ class DWARFLinker {
   bool registerModuleReference(DWARFDie CUDie, const DWARFUnit &Unit,
const DWARFFile &File,
OffsetsStringPool &OffsetsStringPool,
-   UniquingStringPool 
&UniquingStringPoolStringPool,
DeclContextTree &ODRContexts,
uint64_t ModulesEndOffset, unsigned &UnitID,
bool IsLittleEndian, unsigned Indent = 0,
@@ -480,7 +479,6 @@ class DWARFLinker {
 StringRef ModuleName, uint64_t DwoId,
 const DWARFFile &File,
 OffsetsStringPool &OffsetsStringPool,
-UniquingStringPool &UniquingStringPool,
 DeclContextTree &ODRContexts, uint64_t 
ModulesEndOffset,
 unsigned &UnitID, bool IsLittleEndian,
 unsigned Indent = 0, bool Quiet = false);

diff  --git a/llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h 
b/llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h
index 740b1293f618..549a0ce4e4b7 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h
+++ b/llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h
@@ -237,21 +237,6 @@ class CompileUnit {
   const std::vector &getNamespaces() const { return Namespaces; }
   const std::vector &getObjC() const { return ObjC; }
 
-  /// Get the full path for file \a FileNum in the line table
-  StringRef getResolvedPath(unsigned FileNum) {
-if (FileNum >= ResolvedPaths.size())
-  return StringRef();
-return ResolvedPaths[FileNum];
-  }
-
-  /// Set the fully resolved path for the line-table's file \a FileNum
-  /// to \a Path.
-  void setResolvedPath(unsigned FileNum, StringRef Path) {
-if (ResolvedPaths.size() <= FileNum)
-  ResolvedPaths.resize(FileNum + 1);
-ResolvedPaths[FileNum] = Path;
-  }
-
   MCSymbol *getLabelBegin() { return LabelBegin; }
   void setLabelBegin(MCSymbol *S) { LabelBegin = S; }
 
@@ -310,12 +295,6 @@ class CompileUnit {
   std::vector ObjC;
   /// @}
 
-  /// Cached resolved paths from the line table.
-  /// Note, the StringRefs here point in to the intern (uniquing) string pool.
-  /// This means that a StringRef returned here doesn't need to then be uniqued
-  /// for the purposes of getting a unique address for each string.
-  std::vector ResolvedPaths;
-
   /// Is this unit subject to the ODR rule?
   bool HasODR;
 

diff  --git a/llvm/include/llvm/DWARFLinker/DWARFLinkerDeclContext.h 
b/llvm/include/llvm/DWARFLinker/DWARFLinkerDeclContext.h
index e59e15f00a7e..d2274488e85f 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinkerDeclContext.h
+++ b/llvm/include/llvm/DWARFLinker/DWARFLinkerDeclContext.h
@@ -15,6 +15,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/CodeGen/NonRelocatableStringpool.h"
 #include "llvm/DWARFLinker/DWARFLinkerCompileUnit.h"
+#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -31,16 +32,18 @@ class CachedPathResolver {
 public:
   /// Resolve a path by calling realpath and cache its result. The returned
   /// StringRef is interned in the given \p StringPool.
-  

[llvm-branch-commits] [llvm] d9c0b12 - [SCEV] Simplify trunc to zero based on known bits

2021-01-03 Thread Gil Rapaport via llvm-branch-commits

Author: Gil Rapaport
Date: 2021-01-03T13:57:12+02:00
New Revision: d9c0b128e3543d5d30f43019257bfd96ce4cdcd1

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

LOG: [SCEV] Simplify trunc to zero based on known bits

Let getTruncateExpr() short-circuit to zero when the value being truncated is
known to have at least as many trailing zeros as the target type.

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

Added: 


Modified: 
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/trunc-simplify.ll

llvm/test/Transforms/LoopVectorize/dont-fold-tail-for-assumed-divisible-TC.ll

Removed: 




diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp 
b/llvm/lib/Analysis/ScalarEvolution.cpp
index 3c284007cc2d..e807db0e2ac4 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -1222,6 +1222,11 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV 
*Op, Type *Ty,
 return getAddRecExpr(Operands, AddRec->getLoop(), SCEV::FlagAnyWrap);
   }
 
+  // Return zero if truncating to known zeros.
+  uint32_t MinTrailingZeros = GetMinTrailingZeros(Op);
+  if (MinTrailingZeros >= getTypeSizeInBits(Ty))
+return getZero(Ty);
+
   // The cast wasn't folded; create an explicit cast node. We can reuse
   // the existing insert position since if we get here, we won't have
   // made any changes which would invalidate it.

diff  --git a/llvm/test/Analysis/ScalarEvolution/trunc-simplify.ll 
b/llvm/test/Analysis/ScalarEvolution/trunc-simplify.ll
index e4c752b02e0e..d2bc284b3b5d 100644
--- a/llvm/test/Analysis/ScalarEvolution/trunc-simplify.ll
+++ b/llvm/test/Analysis/ScalarEvolution/trunc-simplify.ll
@@ -24,3 +24,25 @@ define i8 @trunc_of_add(i32 %a) {
   %c = trunc i32 %b to i8
   ret i8 %c
 }
+
+; Check that we truncate to zero values assumed to have at least as many
+; trailing zeros as the target type.
+; CHECK-LABEL: @trunc_to_assumed_zeros
+define i8 @trunc_to_assumed_zeros(i32* %p) {
+  %a = load i32, i32* %p
+  %and = and i32 %a, 255
+  %cmp = icmp eq i32 %and, 0
+  tail call void @llvm.assume(i1 %cmp)
+  ; CHECK: %c
+  ; CHECK-NEXT: --> 0
+  %c = trunc i32 %a to i8
+  ; CHECK: %d
+  ; CHECK-NEXT: --> false
+  %d = trunc i32 %a to i1
+  ; CHECK: %e
+  ; CHECK-NEXT: --> (trunc i32 %a to i16)
+  %e = trunc i32 %a to i16
+  ret i8 %c
+}
+
+declare void @llvm.assume(i1 noundef) nofree nosync nounwind willreturn

diff  --git 
a/llvm/test/Transforms/LoopVectorize/dont-fold-tail-for-assumed-divisible-TC.ll 
b/llvm/test/Transforms/LoopVectorize/dont-fold-tail-for-assumed-divisible-TC.ll
index e0a14db9a6d1..69a856f4598f 100644
--- 
a/llvm/test/Transforms/LoopVectorize/dont-fold-tail-for-assumed-divisible-TC.ll
+++ 
b/llvm/test/Transforms/LoopVectorize/dont-fold-tail-for-assumed-divisible-TC.ll
@@ -3,7 +3,7 @@
 
 target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 
-; TODO: Make sure the loop is vectorized under -Os without folding its tail 
based on
+; Make sure the loop is vectorized under -Os without folding its tail based on
 ; its trip-count's lower bits assumed to be zero.
 
 define dso_local void @assumeAlignedTC(i32* noalias nocapture %A, i32* %p) 
optsize {
@@ -13,57 +13,28 @@ define dso_local void @assumeAlignedTC(i32* noalias 
nocapture %A, i32* %p) optsi
 ; CHECK-NEXT:[[AND:%.*]] = and i32 [[N]], 3
 ; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0
 ; CHECK-NEXT:tail call void @llvm.assume(i1 [[CMP]])
-; CHECK-NEXT:br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
+; CHECK-NEXT:[[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N]], 4
+; CHECK-NEXT:br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label 
[[VECTOR_PH:%.*]]
 ; CHECK:   vector.ph:
-; CHECK-NEXT:[[N_RND_UP:%.*]] = add i32 [[N]], 3
-; CHECK-NEXT:[[N_MOD_VF:%.*]] = urem i32 [[N_RND_UP]], 4
-; CHECK-NEXT:[[N_VEC:%.*]] = sub i32 [[N_RND_UP]], [[N_MOD_VF]]
-; CHECK-NEXT:[[TRIP_COUNT_MINUS_1:%.*]] = sub i32 [[N]], 1
-; CHECK-NEXT:[[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> 
poison, i32 [[TRIP_COUNT_MINUS_1]], i32 0
-; CHECK-NEXT:[[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> 
[[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
+; CHECK-NEXT:[[N_MOD_VF:%.*]] = urem i32 [[N]], 4
+; CHECK-NEXT:[[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]
 ; CHECK-NEXT:br label [[VECTOR_BODY:%.*]]
 ; CHECK:   vector.body:
-; CHECK-NEXT:[[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ 
[[INDEX_NEXT:%.*]], [[PRED_STORE_CONTINUE6:%.*]] ]
-; CHECK-NEXT:[[VEC_IND:%.*]] = phi <4 x i32> [ , [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[PRED_STORE_CONTINUE6]] ]
-; CHECK-NEXT:[[TMP0:%.*]] = icmp ule <4 x i32> [[VEC_IND]], 
[[BROADCA

[llvm-branch-commits] [llvm] c5a7e75 - Update *-inseltpoison.ll tests at Transforms/InstCombine/X86 by replacing undef with poison (NFC)

2021-01-03 Thread Juneyoung Lee via llvm-branch-commits

Author: Juneyoung Lee
Date: 2021-01-03T22:40:05+09:00
New Revision: c5a7e75eb6b5129967f9b936425e5fd9633a42f5

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

LOG: Update *-inseltpoison.ll tests at Transforms/InstCombine/X86 by replacing 
undef with poison (NFC)

Added: 


Modified: 
llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-pshufb-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-vector-shifts-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-vpermil-inseltpoison.ll

Removed: 




diff  --git a/llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll 
b/llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
index ff8842cd15ea..4cc89fc80f29 100644
--- a/llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
@@ -5,99 +5,99 @@
 ; UNDEF Elts
 ;
 
-define <8 x i16> @undef_packssdw_128() {
-; CHECK-LABEL: @undef_packssdw_128(
+define <8 x i16> @poison_packssdw_128() {
+; CHECK-LABEL: @poison_packssdw_128(
 ; CHECK-NEXT:ret <8 x i16> undef
 ;
-  %1 = call <8 x i16> @llvm.x86.sse2.packssdw.128(<4 x i32> undef, <4 x i32> 
undef)
+  %1 = call <8 x i16> @llvm.x86.sse2.packssdw.128(<4 x i32> poison, <4 x i32> 
poison)
   ret <8 x i16> %1
 }
 
-define <8 x i16> @undef_packusdw_128() {
-; CHECK-LABEL: @undef_packusdw_128(
+define <8 x i16> @poison_packusdw_128() {
+; CHECK-LABEL: @poison_packusdw_128(
 ; CHECK-NEXT:ret <8 x i16> undef
 ;
-  %1 = call <8 x i16> @llvm.x86.sse41.packusdw(<4 x i32> undef, <4 x i32> 
undef)
+  %1 = call <8 x i16> @llvm.x86.sse41.packusdw(<4 x i32> poison, <4 x i32> 
poison)
   ret <8 x i16> %1
 }
 
-define <16 x i8> @undef_packsswb_128() {
-; CHECK-LABEL: @undef_packsswb_128(
+define <16 x i8> @poison_packsswb_128() {
+; CHECK-LABEL: @poison_packsswb_128(
 ; CHECK-NEXT:ret <16 x i8> undef
 ;
-  %1 = call <16 x i8> @llvm.x86.sse2.packsswb.128(<8 x i16> undef, <8 x i16> 
undef)
+  %1 = call <16 x i8> @llvm.x86.sse2.packsswb.128(<8 x i16> poison, <8 x i16> 
poison)
   ret <16 x i8> %1
 }
 
-define <16 x i8> @undef_packuswb_128() {
-; CHECK-LABEL: @undef_packuswb_128(
+define <16 x i8> @poison_packuswb_128() {
+; CHECK-LABEL: @poison_packuswb_128(
 ; CHECK-NEXT:ret <16 x i8> undef
 ;
-  %1 = call <16 x i8> @llvm.x86.sse2.packuswb.128(<8 x i16> undef, <8 x i16> 
undef)
+  %1 = call <16 x i8> @llvm.x86.sse2.packuswb.128(<8 x i16> poison, <8 x i16> 
poison)
   ret <16 x i8> %1
 }
 
-define <16 x i16> @undef_packssdw_256() {
-; CHECK-LABEL: @undef_packssdw_256(
+define <16 x i16> @poison_packssdw_256() {
+; CHECK-LABEL: @poison_packssdw_256(
 ; CHECK-NEXT:ret <16 x i16> undef
 ;
-  %1 = call <16 x i16> @llvm.x86.avx2.packssdw(<8 x i32> undef, <8 x i32> 
undef)
+  %1 = call <16 x i16> @llvm.x86.avx2.packssdw(<8 x i32> poison, <8 x i32> 
poison)
   ret <16 x i16> %1
 }
 
-define <16 x i16> @undef_packusdw_256() {
-; CHECK-LABEL: @undef_packusdw_256(
+define <16 x i16> @poison_packusdw_256() {
+; CHECK-LABEL: @poison_packusdw_256(
 ; CHECK-NEXT:ret <16 x i16> undef
 ;
-  %1 = call <16 x i16> @llvm.x86.avx2.packusdw(<8 x i32> undef, <8 x i32> 
undef)
+  %1 = call <16 x i16> @llvm.x86.avx2.packusdw(<8 x i32> poison, <8 x i32> 
poison)
   ret <16 x i16> %1
 }
 
-define <32 x i8> @undef_packsswb_256() {
-; CHECK-LABEL: @undef_packsswb_256(
+define <32 x i8> @poison_packsswb_256() {
+; CHECK-LABEL: @poison_packsswb_256(
 ; CHECK-NEXT:ret <32 x i8> undef
 ;
-  %1 = call <32 x i8> @llvm.x86.avx2.packsswb(<16 x i16> undef, <16 x i16> 
undef)
+  %1 = call <32 x i8> @llvm.x86.avx2.packsswb(<16 x i16> poison, <16 x i16> 
poison)
   ret <32 x i8> %1
 }
 
-define <32 x i8> @undef_packuswb_256() {
-; CHECK-LABEL: @undef_packuswb_256(
+define <32 x i8> @poison_packuswb_256() {
+; CHECK-LABEL: @poison_packuswb_256(
 ; CHECK-NEXT:ret <32 x i8> undef
 ;
-  %1 = call <32 x i8> @llvm.x86.avx2.packuswb(<16 x i16> undef, <16 x i16> 
undef)
+  %1 = call <32 x i8> @llvm.x86.avx2.packuswb(<16 x i16> poison, <16 x i16> 
poison)
   ret <32 x i8> %1
 }
 
-define <32 x i16> @undef_packssdw_512() {
-; CHECK-LABEL: @undef_packssdw_512(
+define <32 x i16> @poison_packssdw_512() {
+; CHECK-LABEL: @poison_packssdw_512(
 ; CHECK-NEXT:ret <32 x i16> undef
 ;
-  %1 = call <32 x i16> @llvm.x86.avx512.packssdw.512(<16 x i32> undef, <16 x 
i32> undef)
+  %1 = call <32 x i16> @llvm.x86.avx512.packssdw.512(<16 x i32> poison, <16 x 
i32> poison)
   ret <32 x i16> %1
 }
 
-define <32 x i16> @undef_packusdw_512() {
-; CHECK-LABEL: @undef_packusdw_512(
+define <32 x i16> @poison_packusdw_512() {
+; CHECK-LABEL: @poison_packusdw_512(
 ; CHECK-NEXT

[llvm-branch-commits] [llvm] 1fc992b - [Scalarizer] Use poison as insertelement's placeholder

2021-01-03 Thread Juneyoung Lee via llvm-branch-commits

Author: Juneyoung Lee
Date: 2021-01-04T00:35:28+09:00
New Revision: 1fc992bd864aa7e73615a47e72e82e2cf7ac73ef

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

LOG: [Scalarizer] Use poison as insertelement's placeholder

This patch makes Scalarizer to use poison as insertelement's placeholder.

It contains two changes in Scalarizer.cpp, and the both changes does not change 
the semantics of the optimized program.
It is because the placeholder value (poison) is already completely hidden by 
following insertelement instructions.

The first change at visitBitCastInst() creates poison vector of MidTy and 
consecutively inserts FanIn times,
which is # of elems of MidTy.
The second change at ScalarizerVisitor::finish() creates poison with 
Op->getType(), and it is filled with
Count insertelements.

The test diffs show that the poison value is never exposed after insertelements.

Reviewed By: nikic

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

Added: 


Modified: 
llvm/lib/Transforms/Scalar/Scalarizer.cpp
llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll
llvm/test/Transforms/Scalarizer/basic.ll
llvm/test/Transforms/Scalarizer/constant-insertelement.ll
llvm/test/Transforms/Scalarizer/intrinsics.ll
llvm/test/Transforms/Scalarizer/order-bug-inseltpoison.ll
llvm/test/Transforms/Scalarizer/order-bug.ll
llvm/test/Transforms/Scalarizer/scatter-order.ll
llvm/test/Transforms/Scalarizer/variable-extractelement.ll
llvm/test/Transforms/Scalarizer/variable-insertelement.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp 
b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
index c7fe21f2a3da..c95984fe198f 100644
--- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp
+++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
@@ -733,7 +733,7 @@ bool ScalarizerVisitor::visitBitCastInst(BitCastInst &BCI) {
 auto *MidTy = FixedVectorType::get(SrcVT->getElementType(), FanIn);
 unsigned Op0I = 0;
 for (unsigned ResI = 0; ResI < DstNumElems; ++ResI) {
-  Value *V = UndefValue::get(MidTy);
+  Value *V = PoisonValue::get(MidTy);
   for (unsigned MidI = 0; MidI < FanIn; ++MidI)
 V = Builder.CreateInsertElement(V, Op0[Op0I++], Builder.getInt32(MidI),
 BCI.getName() + ".i" + Twine(ResI)
@@ -932,7 +932,7 @@ bool ScalarizerVisitor::finish() {
 if (!Op->use_empty()) {
   // The value is still needed, so recreate it using a series of
   // InsertElements.
-  Value *Res = UndefValue::get(Op->getType());
+  Value *Res = PoisonValue::get(Op->getType());
   if (auto *Ty = dyn_cast(Op->getType())) {
 BasicBlock *BB = Op->getParent();
 unsigned Count = cast(Ty)->getNumElements();

diff  --git a/llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll 
b/llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll
index d785764e3366..2b501cfd0a7e 100644
--- a/llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll
+++ b/llvm/test/Transforms/Scalarizer/basic-inseltpoison.ll
@@ -33,7 +33,7 @@ define void @f1(<4 x float> %init, <4 x float> *%base, i32 
%count) {
 ; CHECK:   %add.i1 = fadd float %val.i1, %val.i3
 ; CHECK:   %add.i2 = fadd float %acc.i0, %acc.i2
 ; CHECK:   %add.i3 = fadd float %acc.i1, %acc.i3
-; CHECK:   %add.upto0 = insertelement <4 x float> undef, float %add.i0, i32 0
+; CHECK:   %add.upto0 = insertelement <4 x float> poison, float %add.i0, i32 0
 ; CHECK:   %add.upto1 = insertelement <4 x float> %add.upto0, float %add.i1, 
i32 1
 ; CHECK:   %add.upto2 = insertelement <4 x float> %add.upto1, float %add.i2, 
i32 2
 ; CHECK:   %add = insertelement <4 x float> %add.upto2, float %add.i3, i32 3
@@ -247,7 +247,7 @@ define <4 x float> @f6(<4 x float> %x) {
 ; CHECK: %res.i2 = fadd float %x.i2, 3.0{{[e+0]*}}, !fpmath ![[TAG]]
 ; CHECK: %x.i3 = extractelement <4 x float> %x, i32 3
 ; CHECK: %res.i3 = fadd float %x.i3, 4.0{{[e+0]*}}, !fpmath ![[TAG]]
-; CHECK: %res.upto0 = insertelement <4 x float> undef, float %res.i0, i32 0
+; CHECK: %res.upto0 = insertelement <4 x float> poison, float %res.i0, i32 0
 ; CHECK: %res.upto1 = insertelement <4 x float> %res.upto0, float %res.i1, i32 
1
 ; CHECK: %res.upto2 = insertelement <4 x float> %res.upto1, float %res.i2, i32 
2
 ; CHECK: %res = insertelement <4 x float> %res.upto2, float %res.i3, i32 3
@@ -403,7 +403,7 @@ define <4 x float> @f14(<4 x float> %acc, i32 %count) {
 ; CHECK: %this_acc.i2 = phi float [ %acc.i2, %entry ], [ %next_acc.i2, %loop ]
 ; CHECK: %this_acc.i3 = phi float [ %acc.i3, %entry ], [ %next_acc.i3, %loop ]
 ; CHECK: %this_count = phi i32 [ %count, %entry ], [ %next_count, %loop ]
-; CHECK: %this_acc.upto0 = insertelement <4 x float> undef, float 
%this_acc.i0, i32 0
+; CHECK: %this_acc.upto0 = insertelemen

[llvm-branch-commits] [llvm] 578c5a0 - [ArgPromotion] Add test with dead GEP when promoting.

2021-01-03 Thread Florian Hahn via llvm-branch-commits

Author: Florian Hahn
Date: 2021-01-03T15:39:06Z
New Revision: 578c5a0c6e71b0a7b31b3af69ec6fcb176291572

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

LOG: [ArgPromotion] Add test with dead GEP when promoting.

This adds test coverage for the case where we do argument promotion and
there's a dead GEP that should be removed/ignored.

Added: 
llvm/test/Transforms/ArgumentPromotion/aggregate-promote-dead-gep.ll

Modified: 


Removed: 




diff  --git 
a/llvm/test/Transforms/ArgumentPromotion/aggregate-promote-dead-gep.ll 
b/llvm/test/Transforms/ArgumentPromotion/aggregate-promote-dead-gep.ll
new file mode 100644
index ..b9a22b53b372
--- /dev/null
+++ b/llvm/test/Transforms/ArgumentPromotion/aggregate-promote-dead-gep.ll
@@ -0,0 +1,34 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --function-signature --scrub-attributes
+; RUN: opt < %s -argpromotion -S | FileCheck %s
+; RUN: opt < %s -passes=argpromotion -S | FileCheck %s
+
+%T = type { i32, i32, i32, i32 }
+@G = constant %T { i32 0, i32 0, i32 17, i32 25 }
+
+define internal i32 @test(%T* %p) {
+; CHECK-LABEL: define {{[^@]+}}@test
+; CHECK-SAME: (i32 [[P_0_3_VAL:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[V:%.*]] = add i32 [[P_0_3_VAL]], 10
+; CHECK-NEXT:ret i32 [[V]]
+;
+entry:
+  %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
+  %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
+  %a = load i32, i32* %a.gep
+  %v = add i32 %a, 10
+  ret i32 %v
+}
+
+define i32 @caller() {
+; CHECK-LABEL: define {{[^@]+}}@caller() {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[G_IDX:%.*]] = getelementptr [[T:%.*]], %T* @G, i64 0, i32 3
+; CHECK-NEXT:[[G_IDX_VAL:%.*]] = load i32, i32* [[G_IDX]], align 4
+; CHECK-NEXT:[[V:%.*]] = call i32 @test(i32 [[G_IDX_VAL]])
+; CHECK-NEXT:ret i32 [[V]]
+;
+entry:
+  %v = call i32 @test(%T* @G)
+  ret i32 %v
+}



___
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] 2139958 - [InstSimplify] Return poison if insertelement touches out of bounds

2021-01-03 Thread Juneyoung Lee via llvm-branch-commits

Author: Juneyoung Lee
Date: 2021-01-04T00:43:02+09:00
New Revision: 2139958b53440074fcab9bb2de15e6ec13cc18eb

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

LOG: [InstSimplify] Return poison if insertelement touches out of bounds

This is a simple patch that updates InstSimplify to return poison if the index 
is/can be out-of-bounds

Reviewed By: nikic

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

Added: 


Modified: 
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll
llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll
llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll
llvm/test/Transforms/InstSimplify/insertelement.ll
llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll
llvm/test/Transforms/InstSimplify/vscale.ll

Removed: 




diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp 
b/llvm/lib/Analysis/InstructionSimplify.cpp
index 9fed2600b3ab..eb945c60cf94 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4385,16 +4385,16 @@ Value *llvm::SimplifyInsertElementInst(Value *Vec, 
Value *Val, Value *Idx,
   if (VecC && ValC && IdxC)
 return ConstantExpr::getInsertElement(VecC, ValC, IdxC);
 
-  // For fixed-length vector, fold into undef if index is out of bounds.
+  // For fixed-length vector, fold into poison if index is out of bounds.
   if (auto *CI = dyn_cast(Idx)) {
 if (isa(Vec->getType()) &&
 CI->uge(cast(Vec->getType())->getNumElements()))
-  return UndefValue::get(Vec->getType());
+  return PoisonValue::get(Vec->getType());
   }
 
   // If index is undef, it might be out of bounds (see above case)
   if (Q.isUndefValue(Idx))
-return UndefValue::get(Vec->getType());
+return PoisonValue::get(Vec->getType());
 
   // If the scalar is undef, and there is no risk of propagating poison from 
the
   // vector value, simplify to the vector value.

diff  --git a/llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll 
b/llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll
index 9559c61dda00..f3b95ed07d44 100644
--- a/llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll
+++ b/llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll
@@ -34,7 +34,7 @@ declare void @llvm.assume(i1)
 
 define <4 x double> @inselt_bad_index(<4 x double> %a) {
 ; CHECK-LABEL: @inselt_bad_index(
-; CHECK-NEXT:ret <4 x double> undef
+; CHECK-NEXT:ret <4 x double> poison
 ;
   %I = insertelement <4 x double> %a, double 0.0, i64 4294967296
   ret <4 x double> %I

diff  --git 
a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll 
b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll
index b08e4a7db125..eaa83d4c03f4 100644
--- a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll
@@ -54,10 +54,10 @@ define <4 x float> @bazz(<4 x float> %x, i32 %a) {
   ret <4 x float> %ins6
 }
 
-; Out of bounds index folds to undef
+; Out of bounds index folds to poison
 define <4 x float> @bazzz(<4 x float> %x) {
 ; CHECK-LABEL: @bazzz(
-; CHECK-NEXT:ret <4 x float> 
+; CHECK-NEXT:ret <4 x float> 
 ;
   %ins1 = insertelement<4 x float> %x, float 1.0, i32 5
   %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2
@@ -66,7 +66,7 @@ define <4 x float> @bazzz(<4 x float> %x) {
 
 define <4 x float> @ba(<4 x float> %x) {
 ; CHECK-LABEL: @ba(
-; CHECK-NEXT:ret <4 x float> 
+; CHECK-NEXT:ret <4 x float> 
 ;
   %ins1 = insertelement<4 x float> %x, float 1.0, i32 undef
   %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2

diff  --git a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll 
b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll
index 30150af6209b..2635c627c160 100644
--- a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll
+++ b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll
@@ -54,10 +54,10 @@ define <4 x float> @bazz(<4 x float> %x, i32 %a) {
   ret <4 x float> %ins6
 }
 
-; Out of bounds index folds to undef
+; Out of bounds index folds to poison
 define <4 x float> @bazzz(<4 x float> %x) {
 ; CHECK-LABEL: @bazzz(
-; CHECK-NEXT:ret <4 x float> 
+; CHECK-NEXT:ret <4 x float> 
 ;
   %ins1 = insertelement<4 x float> %x, float 1.0, i32 5
   %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2
@@ -66,7 +66,7 @@ define <4 x float> @bazzz(<4 x float> %x) {
 
 define <4 x float> @ba(<4 x float> %x) {
 ; CHECK-LABEL: @ba(
-; CHECK-NEXT:ret <4 x float> 
+; CHECK-NEXT:ret <4 x float> 
 ;
   %ins1 = insertelement<4 x float> %x, float 1.0, i32 undef
   %

[llvm-branch-commits] [llvm] 858b99d - [InstSimplify] Regenerate test checks (NFC)

2021-01-03 Thread Nikita Popov via llvm-branch-commits

Author: Nikita Popov
Date: 2021-01-03T18:09:58+01:00
New Revision: 858b99d774f10fb59a3d9ddb8bcc7dc040490e39

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

LOG: [InstSimplify] Regenerate test checks (NFC)

Added: 


Modified: 
llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
llvm/test/Transforms/InstSimplify/undef.ll

Removed: 




diff  --git 
a/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll 
b/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
index 2c35ed7f3909..a0896b4880bd 100644
--- a/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
+++ b/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
@@ -1,8 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -instsimplify -S | FileCheck %s
 
 declare void @bar()
 
 define void @test1() personality i32 (i32, i64, i8*, i8*)* 
@__gxx_personality_v0 {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:invoke void @bar()
+; CHECK-NEXT:to label [[CONT:%.*]] unwind label [[LPAD:%.*]]
+; CHECK:   cont:
+; CHECK-NEXT:ret void
+; CHECK:   lpad:
+; CHECK-NEXT:[[EX:%.*]] = landingpad { i8*, i32 }
+; CHECK-NEXT:cleanup
+; CHECK-NEXT:resume { i8*, i32 } [[EX]]
+;
 entry:
   invoke void @bar() to label %cont unwind label %lpad
 cont:
@@ -14,42 +26,46 @@ lpad:
   %exc_ptr2 = insertvalue { i8*, i32 } undef, i8* %exc_ptr, 0
   %filter2 = insertvalue { i8*, i32 } %exc_ptr2, i32 %filter, 1
   resume { i8*, i32 } %filter2
-; CHECK-LABEL: @test1(
-; CHECK-NOT: extractvalue
-; CHECK-NOT: insertvalue
 }
 
 declare i32 @__gxx_personality_v0(i32, i64, i8*, i8*)
 
 define { i8, i32 } @test2({ i8*, i32 } %x) {
+; CHECK-LABEL: @test2(
+; CHECK-NEXT:[[EX:%.*]] = extractvalue { i8*, i32 } [[X:%.*]], 1
+; CHECK-NEXT:[[INS:%.*]] = insertvalue { i8, i32 } undef, i32 [[EX]], 1
+; CHECK-NEXT:ret { i8, i32 } [[INS]]
+;
   %ex = extractvalue { i8*, i32 } %x, 1
   %ins = insertvalue { i8, i32 } undef, i32 %ex, 1
   ret { i8, i32 } %ins
-; CHECK-LABEL: @test2(
 }
 
 define i32 @test3(i32 %a, float %b) {
+; CHECK-LABEL: @test3(
+; CHECK-NEXT:ret i32 [[A:%.*]]
+;
   %agg1 = insertvalue {i32, float} undef, i32 %a, 0
   %agg2 = insertvalue {i32, float} %agg1, float %b, 1
   %ev = extractvalue {i32, float} %agg2, 0
   ret i32 %ev
-; CHECK-LABEL: @test3(
-; CHECK: ret i32 %a
 }
 
 define i8 @test4(<8 x i8> %V) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT:[[ADD:%.*]] = add <8 x i8> [[V:%.*]], bitcast (<1 x double> 
 to <8 x i8>)
+; CHECK-NEXT:[[EXTRACT:%.*]] = extractelement <8 x i8> [[ADD]], i32 6
+; CHECK-NEXT:ret i8 [[EXTRACT]]
+;
   %add = add <8 x i8> %V, bitcast (double 0x319BEB8FD172E36 to <8 x i8>)
   %extract = extractelement <8 x i8> %add, i32 6
   ret i8 %extract
-; CHECK-LABEL: @test4(
-; CHECK: %[[add:.*]] = add <8 x i8> %V, bitcast (<1 x double>  to <8 x i8>)
-; CHECK-NEXT: %[[extract:.*]] = extractelement <8 x i8> %[[add]], i32 6
-; CHECK-NEXT: ret i8 %[[extract]]
 }
 
 define i32 @test5(<4 x i32> %V) {
+; CHECK-LABEL: @test5(
+; CHECK-NEXT:ret i32 undef
+;
   %extract = extractelement <4 x i32> %V, i32 undef
   ret i32 %extract
 }
-; CHECK-LABEL: @test5(
-; CHECK: ret i32 undef

diff  --git a/llvm/test/Transforms/InstSimplify/undef.ll 
b/llvm/test/Transforms/InstSimplify/undef.ll
index 2d88f9f83ad7..b7c69a5b4e7f 100644
--- a/llvm/test/Transforms/InstSimplify/undef.ll
+++ b/llvm/test/Transforms/InstSimplify/undef.ll
@@ -1,8 +1,9 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -instsimplify -S < %s | FileCheck %s
 
 define i64 @test0() {
 ; CHECK-LABEL: @test0(
-; CHECK: ret i64 undef
+; CHECK-NEXT:ret i64 undef
 ;
   %r = mul i64 undef, undef
   ret i64 %r
@@ -10,7 +11,7 @@ define i64 @test0() {
 
 define i64 @test1() {
 ; CHECK-LABEL: @test1(
-; CHECK: ret i64 undef
+; CHECK-NEXT:ret i64 undef
 ;
   %r = mul i64 3, undef
   ret i64 %r
@@ -18,7 +19,7 @@ define i64 @test1() {
 
 define i64 @test2() {
 ; CHECK-LABEL: @test2(
-; CHECK: ret i64 undef
+; CHECK-NEXT:ret i64 undef
 ;
   %r = mul i64 undef, 3
   ret i64 %r
@@ -26,7 +27,7 @@ define i64 @test2() {
 
 define i64 @test3() {
 ; CHECK-LABEL: @test3(
-; CHECK: ret i64 0
+; CHECK-NEXT:ret i64 0
 ;
   %r = mul i64 undef, 6
   ret i64 %r
@@ -34,7 +35,7 @@ define i64 @test3() {
 
 define i64 @test4() {
 ; CHECK-LABEL: @test4(
-; CHECK: ret i64 0
+; CHECK-NEXT:ret i64 0
 ;
   %r = mul i64 6, undef
   ret i64 %r
@@ -42,7 +43,7 @@ define i64 @test4() {
 
 define i64 @test5() {
 ; CHECK-LABEL: @test5(
-; CHECK: ret i64 undef
+; CHECK-NEXT:ret i64 undef
 ;
   %r = and i64 undef, undef
   ret i64 %

[llvm-branch-commits] [llvm] 49c2d70 - [X86] Make deinterleave8bitStride3 use unary CreateShuffleVector

2021-01-03 Thread Juneyoung Lee via llvm-branch-commits

Author: Juneyoung Lee
Date: 2021-01-04T02:10:51+09:00
New Revision: 49c2d703d344e8d259a4aee38c8ade1df34bc54a

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

LOG: [X86] Make deinterleave8bitStride3 use unary CreateShuffleVector

This patch makes X86InterleavedAccessGroup::deinterleave8bitStride3 use the 
unary CreateShuffleVector.

This is a continuation of D93923. There were a few missing replacements.

IIUC, this patch does not cause change in the generated programs' semantics 
because the
function inserts shufflevectors that only choose elements from the first vector.

Reviewed By: nikic

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

Added: 


Modified: 
llvm/lib/Target/X86/X86InterleavedAccess.cpp
llvm/test/Transforms/InterleavedAccess/X86/interleavedLoad-inseltpoison.ll
llvm/test/Transforms/InterleavedAccess/X86/interleavedLoad.ll
llvm/test/Transforms/InterleavedAccess/X86/interleavedStore-inseltpoison.ll
llvm/test/Transforms/InterleavedAccess/X86/interleavedStore.ll

Removed: 




diff  --git a/llvm/lib/Target/X86/X86InterleavedAccess.cpp 
b/llvm/lib/Target/X86/X86InterleavedAccess.cpp
index 5546f27b9488..95655dd4723b 100644
--- a/llvm/lib/Target/X86/X86InterleavedAccess.cpp
+++ b/llvm/lib/Target/X86/X86InterleavedAccess.cpp
@@ -44,8 +44,8 @@ namespace {
 ///  E.g. A group of interleaving access loads (Factor = 2; accessing every
 ///   other element)
 ///%wide.vec = load <8 x i32>, <8 x i32>* %ptr
-///%v0 = shuffle <8 x i32> %wide.vec, <8 x i32> undef, <0, 2, 4, 6>
-///%v1 = shuffle <8 x i32> %wide.vec, <8 x i32> undef, <1, 3, 5, 7>
+///%v0 = shuffle <8 x i32> %wide.vec, <8 x i32> poison, <0, 2, 4, 6>
+///%v1 = shuffle <8 x i32> %wide.vec, <8 x i32> poison, <1, 3, 5, 7>
 class X86InterleavedAccessGroup {
   /// Reference to the wide-load instruction of an interleaved access
   /// group.
@@ -576,8 +576,7 @@ void X86InterleavedAccessGroup::deinterleave8bitStride3(
   // Vec[2]= b5 b6 b7 c5 c6 c7 a6 a7
 
   for (int i = 0; i < 3; i++)
-Vec[i] = Builder.CreateShuffleVector(
-Vec[i], UndefValue::get(Vec[0]->getType()), VPShuf);
+Vec[i] = Builder.CreateShuffleVector(Vec[i], VPShuf);
 
   // TempVector[0]= a6 a7 a0 a1 a2 b0 b1 b2
   // TempVector[1]= c0 c1 c2 c3 c4 a3 a4 a5
@@ -599,10 +598,8 @@ void X86InterleavedAccessGroup::deinterleave8bitStride3(
   // TransposedMatrix[1]= b0 b1 b2 b3 b4 b5 b6 b7
   // TransposedMatrix[2]= c0 c1 c2 c3 c4 c5 c6 c7
 
-  Value *TempVec = Builder.CreateShuffleVector(
-  Vec[1], UndefValue::get(Vec[1]->getType()), VPAlign3);
-  TransposedMatrix[0] = Builder.CreateShuffleVector(
-  Vec[0], UndefValue::get(Vec[1]->getType()), VPAlign2);
+  Value *TempVec = Builder.CreateShuffleVector(Vec[1], VPAlign3);
+  TransposedMatrix[0] = Builder.CreateShuffleVector(Vec[0], VPAlign2);
   TransposedMatrix[1] = VecElems == 8 ? Vec[2] : TempVec;
   TransposedMatrix[2] = VecElems == 8 ? TempVec : Vec[2];
 }
@@ -659,10 +656,8 @@ void X86InterleavedAccessGroup::interleave8bitStride3(
   // Vec[1]= c5 c6 c7 c0 c1 c2 c3 c4
   // Vec[2]= b0 b1 b2 b3 b4 b5 b6 b7
 
-  Vec[0] = Builder.CreateShuffleVector(
-  InVec[0], UndefValue::get(InVec[0]->getType()), VPAlign2);
-  Vec[1] = Builder.CreateShuffleVector(
-  InVec[1], UndefValue::get(InVec[1]->getType()), VPAlign3);
+  Vec[0] = Builder.CreateShuffleVector(InVec[0], VPAlign2);
+  Vec[1] = Builder.CreateShuffleVector(InVec[1], VPAlign3);
   Vec[2] = InVec[2];
 
   // Vec[0]= a6 a7 a0 a1 a2 b0 b1 b2

diff  --git 
a/llvm/test/Transforms/InterleavedAccess/X86/interleavedLoad-inseltpoison.ll 
b/llvm/test/Transforms/InterleavedAccess/X86/interleavedLoad-inseltpoison.ll
index f713918292dc..7fbf34aa1db4 100644
--- a/llvm/test/Transforms/InterleavedAccess/X86/interleavedLoad-inseltpoison.ll
+++ b/llvm/test/Transforms/InterleavedAccess/X86/interleavedLoad-inseltpoison.ll
@@ -20,17 +20,17 @@ define <32 x i8> @interleaved_load_vf32_i8_stride3(<96 x 
i8>* %ptr){
 ; CHECK-NEXT:[[TMP14:%.*]] = shufflevector <16 x i8> [[TMP3]], <16 x i8> 
[[TMP9]], <32 x i32> 
 ; CHECK-NEXT:[[TMP15:%.*]] = shufflevector <16 x i8> [[TMP5]], <16 x i8> 
[[TMP11]], <32 x i32> 
 ; CHECK-NEXT:[[TMP16:%.*]] = shufflevector <16 x i8> [[TMP7]], <16 x i8> 
[[TMP13]], <32 x i32> 
-; CHECK-NEXT:[[TMP17:%.*]] = shufflevector <32 x i8> [[TMP14]], <32 x i8> 
undef, <32 x i32> 
-; CHECK-NEXT:[[TMP18:%.*]] = shufflevector <32 x i8> [[TMP15]], <32 x i8> 
undef, <32 x i32> 
-; CHECK-NEXT:[[TMP19:%.*]] = shufflevector <32 x i8> [[TMP16]], <32 x i8> 
undef, <32 x i32> 
+; CHECK-NEXT:[[TMP17:%.*]] = shufflevector <32 x i8> [[TMP14]], <32 x i8> 
poison, <32 x i32> 
+; CHECK-NEXT:[[TMP18:%.*]] = shufflevector <32 x i8> [[TMP15]], <32 x i8> 
p

[llvm-branch-commits] [llvm] c6ad00d - [InstSimplify] Return poison for out of bounds extractelement

2021-01-03 Thread Nikita Popov via llvm-branch-commits

Author: Nikita Popov
Date: 2021-01-03T18:15:58+01:00
New Revision: c6ad00d709853e378cd70e34e755942f9d6f0c8f

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

LOG: [InstSimplify] Return poison for out of bounds extractelement

This is the same change as D93990, but for extractelement rather
than insertelement.

> If idx exceeds the length of val for a fixed-length vector, the
> result is a poison value. For a scalable vector, if the value of
> idx exceeds the runtime length of the vector, the result is a
> poison value.

Added: 


Modified: 
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
llvm/test/Transforms/InstCombine/extractelement.ll
llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
llvm/test/Transforms/InstSimplify/extract-element.ll
llvm/test/Transforms/InstSimplify/undef.ll
llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll
llvm/test/Transforms/InstSimplify/vscale.ll

Removed: 




diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp 
b/llvm/lib/Analysis/InstructionSimplify.cpp
index eb945c60cf94..16b5fd5436f9 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4464,15 +4464,15 @@ static Value *SimplifyExtractElementInst(Value *Vec, 
Value *Idx,
 // For fixed-length vector, fold into undef if index is out of bounds.
 if (isa(VecVTy) &&
 IdxC->getValue().uge(cast(VecVTy)->getNumElements()))
-  return UndefValue::get(VecVTy->getElementType());
+  return PoisonValue::get(VecVTy->getElementType());
 if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue()))
   return Elt;
   }
 
   // An undef extract index can be arbitrarily chosen to be an out-of-range
-  // index value, which would result in the instruction being undef.
+  // index value, which would result in the instruction being poison.
   if (Q.isUndefValue(Idx))
-return UndefValue::get(VecVTy->getElementType());
+return PoisonValue::get(VecVTy->getElementType());
 
   return nullptr;
 }

diff  --git a/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll 
b/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
index 82c1a5c98294..f3fad9bb375c 100644
--- a/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
@@ -4,7 +4,7 @@
 
 define i32 @extractelement_out_of_range(<2 x i32> %x) {
 ; ANY-LABEL: @extractelement_out_of_range(
-; ANY-NEXT:ret i32 undef
+; ANY-NEXT:ret i32 poison
 ;
   %E1 = extractelement <2 x i32> %x, i8 16
   ret i32 %E1
@@ -319,7 +319,7 @@ define <4 x double> @invalid_extractelement(<2 x double> 
%a, <4 x double> %b, do
 ; ANY-NEXT:[[T4:%.*]] = shufflevector <4 x double> [[B:%.*]], <4 x double> 
[[TMP1]], <4 x i32> 
 ; ANY-NEXT:[[E:%.*]] = extractelement <4 x double> [[B]], i32 1
 ; ANY-NEXT:store double [[E]], double* [[P:%.*]], align 8
-; ANY-NEXT:[[R:%.*]] = insertelement <4 x double> [[T4]], double undef, 
i64 0
+; ANY-NEXT:[[R:%.*]] = insertelement <4 x double> [[T4]], double poison, 
i64 0
 ; ANY-NEXT:ret <4 x double> [[R]]
 ;
   %t3 = extractelement <2 x double> %a, i32 0

diff  --git a/llvm/test/Transforms/InstCombine/extractelement.ll 
b/llvm/test/Transforms/InstCombine/extractelement.ll
index 76b7d28b2c09..7d36618452f5 100644
--- a/llvm/test/Transforms/InstCombine/extractelement.ll
+++ b/llvm/test/Transforms/InstCombine/extractelement.ll
@@ -4,7 +4,7 @@
 
 define i32 @extractelement_out_of_range(<2 x i32> %x) {
 ; ANY-LABEL: @extractelement_out_of_range(
-; ANY-NEXT:ret i32 undef
+; ANY-NEXT:ret i32 poison
 ;
   %E1 = extractelement <2 x i32> %x, i8 16
   ret i32 %E1
@@ -319,7 +319,7 @@ define <4 x double> @invalid_extractelement(<2 x double> 
%a, <4 x double> %b, do
 ; ANY-NEXT:[[T4:%.*]] = shufflevector <4 x double> [[B:%.*]], <4 x double> 
[[TMP1]], <4 x i32> 
 ; ANY-NEXT:[[E:%.*]] = extractelement <4 x double> [[B]], i32 1
 ; ANY-NEXT:store double [[E]], double* [[P:%.*]], align 8
-; ANY-NEXT:[[R:%.*]] = insertelement <4 x double> [[T4]], double undef, 
i64 0
+; ANY-NEXT:[[R:%.*]] = insertelement <4 x double> [[T4]], double poison, 
i64 0
 ; ANY-NEXT:ret <4 x double> [[R]]
 ;
   %t3 = extractelement <2 x double> %a, i32 0

diff  --git 
a/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll 
b/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
index a0896b4880bd..78acdf27de1a 100644
--- a/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
+++ b/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
@@ -64,7 +64,7 @@ define i8 @test4(<8 x i8> %V) {
 
 define i32 

[llvm-branch-commits] [llvm] f094d65 - [InstSimplify] Fix addo/subo with undef (PR43188)

2021-01-03 Thread Nikita Popov via llvm-branch-commits

Author: Nikita Popov
Date: 2021-01-03T18:51:49+01:00
New Revision: f094d65beaa492e845b03561eddd75b5be653a01

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

LOG: [InstSimplify] Fix addo/subo with undef (PR43188)

We can't fold the first result to undef, because not all values
may be reachable under the constraint that no overflow occurred.
Use the same folds we do for saturated math instead.

Proofs:
uaddo: https://alive2.llvm.org/ce/z/zf55N_
saddo: https://alive2.llvm.org/ce/z/a_xPgS
usubo: https://alive2.llvm.org/ce/z/DmRqwt
ssubo: https://alive2.llvm.org/ce/z/8ag7U-

Added: 


Modified: 
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/with_overflow.ll
llvm/test/Transforms/InstSimplify/call.ll

Removed: 




diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp 
b/llvm/lib/Analysis/InstructionSimplify.cpp
index 16b5fd5436f9..4706969eafc0 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5444,19 +5444,19 @@ static Value *simplifyBinaryIntrinsic(Function *F, 
Value *Op0, Value *Op1,
   case Intrinsic::usub_with_overflow:
   case Intrinsic::ssub_with_overflow:
 // X - X -> { 0, false }
-if (Op0 == Op1)
+// X - undef -> { 0, false }
+// undef - X -> { 0, false }
+if (Op0 == Op1 || Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
   return Constant::getNullValue(ReturnType);
-LLVM_FALLTHROUGH;
+break;
   case Intrinsic::uadd_with_overflow:
   case Intrinsic::sadd_with_overflow:
-// X - undef -> { undef, false }
-// undef - X -> { undef, false }
-// X + undef -> { undef, false }
-// undef + x -> { undef, false }
+// X + undef -> { -1, false }
+// undef + x -> { -1, false }
 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1)) {
   return ConstantStruct::get(
   cast(ReturnType),
-  {UndefValue::get(ReturnType->getStructElementType(0)),
+  {Constant::getAllOnesValue(ReturnType->getStructElementType(0)),
Constant::getNullValue(ReturnType->getStructElementType(1))});
 }
 break;

diff  --git a/llvm/test/Transforms/InstCombine/with_overflow.ll 
b/llvm/test/Transforms/InstCombine/with_overflow.ll
index 84b5042e6186..4553c9f56965 100644
--- a/llvm/test/Transforms/InstCombine/with_overflow.ll
+++ b/llvm/test/Transforms/InstCombine/with_overflow.ll
@@ -61,7 +61,7 @@ define i8 @uaddtest3(i8 %A, i8 %B, i1* %overflowPtr) {
 define i8 @uaddtest4(i8 %A, i1* %overflowPtr) {
 ; CHECK-LABEL: @uaddtest4(
 ; CHECK-NEXT:store i1 false, i1* [[OVERFLOWPTR:%.*]], align 1
-; CHECK-NEXT:ret i8 undef
+; CHECK-NEXT:ret i8 -1
 ;
   %x = call { i8, i1 } @llvm.uadd.with.overflow.i8(i8 undef, i8 %A)
   %y = extractvalue { i8, i1 } %x, 0

diff  --git a/llvm/test/Transforms/InstSimplify/call.ll 
b/llvm/test/Transforms/InstSimplify/call.ll
index 841582ab8974..bb7410ada7d5 100644
--- a/llvm/test/Transforms/InstSimplify/call.ll
+++ b/llvm/test/Transforms/InstSimplify/call.ll
@@ -29,7 +29,7 @@ define i8 @test_uadd2() {
 
 define {i8, i1} @test_uadd3(i8 %v) {
 ; CHECK-LABEL: @test_uadd3(
-; CHECK-NEXT:ret { i8, i1 } { i8 undef, i1 false }
+; CHECK-NEXT:ret { i8, i1 } { i8 -1, i1 false }
 ;
   %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %v, i8 undef)
   ret {i8, i1} %result
@@ -37,7 +37,7 @@ define {i8, i1} @test_uadd3(i8 %v) {
 
 define {i8, i1} @test_uadd3_poison(i8 %v) {
 ; CHECK-LABEL: @test_uadd3_poison(
-; CHECK-NEXT:ret { i8, i1 } { i8 undef, i1 false }
+; CHECK-NEXT:ret { i8, i1 } { i8 -1, i1 false }
 ;
   %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %v, i8 poison)
   ret {i8, i1} %result
@@ -45,7 +45,7 @@ define {i8, i1} @test_uadd3_poison(i8 %v) {
 
 define {i8, i1} @test_uadd4(i8 %v) {
 ; CHECK-LABEL: @test_uadd4(
-; CHECK-NEXT:ret { i8, i1 } { i8 undef, i1 false }
+; CHECK-NEXT:ret { i8, i1 } { i8 -1, i1 false }
 ;
   %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 undef, i8 %v)
   ret {i8, i1} %result
@@ -53,7 +53,7 @@ define {i8, i1} @test_uadd4(i8 %v) {
 
 define {i8, i1} @test_uadd4_poison(i8 %v) {
 ; CHECK-LABEL: @test_uadd4_poison(
-; CHECK-NEXT:ret { i8, i1 } { i8 undef, i1 false }
+; CHECK-NEXT:ret { i8, i1 } { i8 -1, i1 false }
 ;
   %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 poison, i8 %v)
   ret {i8, i1} %result
@@ -79,7 +79,7 @@ define i8 @test_sadd2() {
 
 define {i8, i1} @test_sadd3(i8 %v) {
 ; CHECK-LABEL: @test_sadd3(
-; CHECK-NEXT:ret { i8, i1 } { i8 undef, i1 false }
+; CHECK-NEXT:ret { i8, i1 } { i8 -1, i1 false }
 ;
   %result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 %v, i8 undef)
   ret {i8, i1} %result
@@ -87,7 +87,7 @@ define {i8, i1} @test_sadd3(i8 %v) {
 
 define {i8, i1} @test_sadd3_poison(i8 %v) 

[llvm-branch-commits] [llvm] 985f899 - [Target] Use llvm::append_range (NFC)

2021-01-03 Thread Kazu Hirata via llvm-branch-commits

Author: Kazu Hirata
Date: 2021-01-03T09:57:43-08:00
New Revision: 985f899bf2cc70aeb383a46c6a84aa634677bca2

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

LOG: [Target] Use llvm::append_range (NFC)

Added: 


Modified: 
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
llvm/lib/Target/AMDGPU/R600MachineScheduler.cpp
llvm/lib/Target/AMDGPU/SIMachineScheduler.cpp
llvm/lib/Target/BPF/BPFAdjustOpt.cpp
llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86InstrInfo.cpp

Removed: 




diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
index 9ea8b3265b0d..7232548bbb85 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
@@ -392,8 +392,7 @@ bool AMDGPUUnifyDivergentExitNodes::runOnFunction(Function 
&F) {
   // uniformly reached block with the "done" bit cleared.
   auto BlocksToUnify = std::move(ReturningBlocks);
   if (InsertExport) {
-BlocksToUnify.insert(BlocksToUnify.end(), 
UniformlyReachedRetBlocks.begin(),
- UniformlyReachedRetBlocks.end());
+llvm::append_range(BlocksToUnify, UniformlyReachedRetBlocks);
   }
 
   unifyReturnBlockSet(F, DTU, BlocksToUnify, InsertExport, TTI,

diff  --git a/llvm/lib/Target/AMDGPU/R600MachineScheduler.cpp 
b/llvm/lib/Target/AMDGPU/R600MachineScheduler.cpp
index d7d53c644f33..7382c2f076e4 100644
--- a/llvm/lib/Target/AMDGPU/R600MachineScheduler.cpp
+++ b/llvm/lib/Target/AMDGPU/R600MachineScheduler.cpp
@@ -45,7 +45,7 @@ void R600SchedStrategy::initialize(ScheduleDAGMI *dag) {
 void R600SchedStrategy::MoveUnits(std::vector &QSrc,
   std::vector &QDst)
 {
-  QDst.insert(QDst.end(), QSrc.begin(), QSrc.end());
+  llvm::append_range(QDst, QSrc);
   QSrc.clear();
 }
 

diff  --git a/llvm/lib/Target/AMDGPU/SIMachineScheduler.cpp 
b/llvm/lib/Target/AMDGPU/SIMachineScheduler.cpp
index a8b607618946..ee119ff71e96 100644
--- a/llvm/lib/Target/AMDGPU/SIMachineScheduler.cpp
+++ b/llvm/lib/Target/AMDGPU/SIMachineScheduler.cpp
@@ -763,8 +763,7 @@ void SIScheduleBlockCreator::colorHighLatenciesGroups() {
   // depend (order dependency) on one of the
   // instruction in the block, and are required for the
   // high latency instruction we add.
-  AdditionalElements.insert(AdditionalElements.end(),
-SubGraph.begin(), SubGraph.end());
+  llvm::append_range(AdditionalElements, SubGraph);
 }
   }
   if (CompatibleGroup) {

diff  --git a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp 
b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
index 928b591b2274..da543e7eba53 100644
--- a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
+++ b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
@@ -301,7 +301,7 @@ bool BPFAdjustOptImpl::avoidSpeculation(Instruction &I) {
   if (!isCandidate || Candidates.empty())
 return false;
 
-  PassThroughs.insert(PassThroughs.end(), Candidates.begin(), 
Candidates.end());
+  llvm::append_range(PassThroughs, Candidates);
   return true;
 }
 

diff  --git a/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp 
b/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
index 04cd432f56c5..11e7d5a17fa9 100644
--- a/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
@@ -447,7 +447,7 @@ static void nodes_for_root(GepNode *Root, NodeChildrenMap 
&NCM,
   Work.erase(First);
   NodeChildrenMap::iterator CF = NCM.find(N);
   if (CF != NCM.end()) {
-Work.insert(Work.end(), CF->second.begin(), CF->second.end());
+llvm::append_range(Work, CF->second);
 Nodes.insert(CF->second.begin(), CF->second.end());
   }
 }
@@ -1145,7 +1145,7 @@ void HexagonCommonGEP::getAllUsersForNode(GepNode *Node, 
ValueVect &Values,
 NodeChildrenMap::iterator CF = NCM.find(N);
 if (CF != NCM.end()) {
   NodeVect &Cs = CF->second;
-  Work.insert(Work.end(), Cs.begin(), Cs.end());
+  llvm::append_range(Work, Cs);
 }
   }
 }

diff  --git a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp 
b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
index 52b0a1a58c19..056a5a83a0a6 100644
--- a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
@@ -585,7 +585,7 @@ auto AlignVectors::createLoadGroups(const AddrList &Group) 
const -> MoveList {
 if (llvm::any_of(Deps, inAddrMap))
   return false;
 Move.Main.push_back(Info.Inst);
-Move.Deps.insert(Move.Deps.end(), Deps.begin(), Deps.end());
+llvm::append_range(Move.Deps, Deps);
 

[llvm-branch-commits] [llvm] 0e219b6 - [Target] Construct SmallVector with iterator ranges (NFC)

2021-01-03 Thread Kazu Hirata via llvm-branch-commits

Author: Kazu Hirata
Date: 2021-01-03T09:57:45-08:00
New Revision: 0e219b6443b2a1359cf0096e96b1e74eb60613fc

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

LOG: [Target] Construct SmallVector with iterator ranges (NFC)

Added: 


Modified: 
llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp

Removed: 




diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index b7862f6ef9a4..033fdc7b0886 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -920,7 +920,7 @@ static Value 
*simplifyAMDGCNMemoryIntrinsicDemanded(InstCombiner &IC,
   IC.Builder.SetInsertPoint(&II);
 
   // Assume the arguments are unchanged and later override them, if needed.
-  SmallVector Args(II.arg_begin(), II.arg_end());
+  SmallVector Args(II.args());
 
   if (DMaskIdx < 0) {
 // Buffer case.

diff  --git a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp 
b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
index d6c151d3d2cc..46ee2eb2ed0f 100644
--- a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
@@ -364,8 +364,7 @@ bool searchPredecessors(const MachineBasicBlock *MBB,
 return false;
 
   DenseSet Visited;
-  SmallVector Worklist(MBB->pred_begin(),
-   MBB->pred_end());
+  SmallVector Worklist(MBB->predecessors());
 
   while (!Worklist.empty()) {
 MachineBasicBlock *MBB = Worklist.pop_back_val();

diff  --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index c7abc585d0d1..ea22e0fa16ab 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -6001,8 +6001,8 @@ SDValue SITargetLowering::lowerImage(SDValue Op,
   unsigned IntrOpcode = Intr->BaseOpcode;
   bool IsGFX10Plus = AMDGPU::isGFX10Plus(*Subtarget);
 
-  SmallVector ResultTypes(Op->value_begin(), Op->value_end());
-  SmallVector OrigResultTypes(Op->value_begin(), Op->value_end());
+  SmallVector ResultTypes(Op->values());
+  SmallVector OrigResultTypes(Op->values());
   bool IsD16 = false;
   bool IsG16 = false;
   bool IsA16 = false;

diff  --git a/llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp 
b/llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp
index 563a52f997dd..6366fcff6637 100644
--- a/llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp
+++ b/llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp
@@ -181,8 +181,7 @@ char &llvm::SILowerControlFlowID = SILowerControlFlow::ID;
 static bool hasKill(const MachineBasicBlock *Begin,
 const MachineBasicBlock *End, const SIInstrInfo *TII) {
   DenseSet Visited;
-  SmallVector Worklist(Begin->succ_begin(),
-   Begin->succ_end());
+  SmallVector Worklist(Begin->successors());
 
   while (!Worklist.empty()) {
 MachineBasicBlock *MBB = Worklist.pop_back_val();

diff  --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp 
b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index a50bb623092a..6eb1bdffdac4 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -10401,8 +10401,7 @@ void 
ARMTargetLowering::EmitSjLjDispatchBlock(MachineInstr &MI,
 
 // Remove the landing pad successor from the invoke block and replace it
 // with the new dispatch block.
-SmallVector Successors(BB->succ_begin(),
-  BB->succ_end());
+SmallVector Successors(BB->successors());
 while (!Successors.empty()) {
   MachineBasicBlock *SMBB = Successors.pop_back_val();
   if (SMBB->isEHPad()) {

diff  --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp 
b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
index b556af84f140..0dc0afe271d1 100644
--- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
@@ -2000,8 +2000,7 @@ void ARMTTIImpl::getUnrollingPreferences(Loop *L, 
ScalarEvolution &SE,
 return;
   }
 
-  SmallVector Operands(I.value_op_begin(),
-I.value_op_end());
+  SmallVector Operands(I.operand_values());
   Cost +=
 getUserCost(&I, Operands, TargetTransformInfo::TCK_SizeAndLatency);
 }

diff  --git a/llvm/lib/

[llvm-branch-commits] [llvm] ba82c0b - [llvm] Call *(Set|Map)::erase directly (NFC)

2021-01-03 Thread Kazu Hirata via llvm-branch-commits

Author: Kazu Hirata
Date: 2021-01-03T09:57:47-08:00
New Revision: ba82c0b3157b7397c938215b6a0582acc324c760

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

LOG: [llvm] Call *(Set|Map)::erase directly (NFC)

We can erase an item in a set or map without checking its membership
first.

Added: 


Modified: 
llvm/lib/Analysis/AssumptionCache.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/Transforms/IPO/IROutliner.cpp
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/lib/Transforms/Scalar/GVNSink.cpp

Removed: 




diff  --git a/llvm/lib/Analysis/AssumptionCache.cpp 
b/llvm/lib/Analysis/AssumptionCache.cpp
index bb1ac616ee7f..70053fdf8d30 100644
--- a/llvm/lib/Analysis/AssumptionCache.cpp
+++ b/llvm/lib/Analysis/AssumptionCache.cpp
@@ -167,9 +167,7 @@ void AssumptionCache::unregisterAssumption(CallInst *CI) {
 }
 
 void AssumptionCache::AffectedValueCallbackVH::deleted() {
-  auto AVI = AC->AffectedValues.find(getValPtr());
-  if (AVI != AC->AffectedValues.end())
-AC->AffectedValues.erase(AVI);
+  AC->AffectedValues.erase(getValPtr());
   // 'this' now dangles!
 }
 

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp 
b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 6127c503404f..b790434576cb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -788,14 +788,9 @@ static void collectCallSiteParameters(const MachineInstr 
*CallMI,
   }
 
   // Do not emit CSInfo for undef forwarding registers.
-  for (auto &MO : CallMI->uses()) {
-if (!MO.isReg() || !MO.isUndef())
-  continue;
-auto It = ForwardedRegWorklist.find(MO.getReg());
-if (It == ForwardedRegWorklist.end())
-  continue;
-ForwardedRegWorklist.erase(It);
-  }
+  for (auto &MO : CallMI->uses())
+if (MO.isReg() && MO.isUndef())
+  ForwardedRegWorklist.erase(MO.getReg());
 
   // We erase, from the ForwardedRegWorklist, those forwarding registers for
   // which we successfully describe a loaded value (by using

diff  --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp 
b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index d64a8f26519f..71dbe8d44ba7 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -3160,9 +3160,7 @@ class PhiNodeSet {
   /// \returns whether the element is actually removed, i.e. was in the
   /// collection before the operation.
   bool erase(PHINode *Ptr) {
-auto it = NodeMap.find(Ptr);
-if (it != NodeMap.end()) {
-  NodeMap.erase(Ptr);
+if (NodeMap.erase(Ptr)) {
   SkipRemovedElements(FirstValidElement);
   return true;
 }

diff  --git a/llvm/lib/Transforms/IPO/IROutliner.cpp 
b/llvm/lib/Transforms/IPO/IROutliner.cpp
index 01605769bcff..e506d84b2c29 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -1027,9 +1027,7 @@ alignOutputBlockWithAggFunc(OutlinableGroup &OG, 
OutlinableRegion &Region,
 
 // If we have found one of the stored values for output, replace the value
 // with the corresponding one from the overall function.
-if (GVN.hasValue() &&
-ValuesToFind.find(GVN.getValue()) != ValuesToFind.end()) {
-  ValuesToFind.erase(GVN.getValue());
+if (GVN.hasValue() && ValuesToFind.erase(GVN.getValue())) {
   V->replaceAllUsesWith(OverallFunctionInsts[Idx]);
   if (ValuesToFind.size() == 0)
 break;

diff  --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index 448ff498b110..e9cf97398a8b 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -1920,11 +1920,8 @@ uint32_t GVN::ValueTable::phiTranslateImpl(const 
BasicBlock *Pred,
 /// again.
 void GVN::ValueTable::eraseTranslateCacheEntry(uint32_t Num,
const BasicBlock &CurrBlock) {
-  for (const BasicBlock *Pred : predecessors(&CurrBlock)) {
-auto FindRes = PhiTranslateTable.find({Num, Pred});
-if (FindRes != PhiTranslateTable.end())
-  PhiTranslateTable.erase(FindRes);
-  }
+  for (const BasicBlock *Pred : predecessors(&CurrBlock))
+PhiTranslateTable.erase({Num, Pred});
 }
 
 // In order to find a leader for a given value number at a

diff  --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp 
b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index 5a34ad18158b..1cc10ca4dce0 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -692,10 +692,8 @@ Optional 
GVNSink::analyzeInstructionForSinking(
   ModelledPHI NewPHI(NewInsts, ActivePreds);
 
   // Does sinking this instruction render previous PHIs redundant?
-  if (NeededPHIs.find(NewPHI) != NeededPHIs.end()) {
-NeededPHIs.erase(NewPHI);
+  if (NeededPHIs.e

[llvm-branch-commits] [llvm] 766cf7f - [InstSimplify] Fold division by zero to poison

2021-01-03 Thread Nikita Popov via llvm-branch-commits

Author: Nikita Popov
Date: 2021-01-03T20:52:45+01:00
New Revision: 766cf7f32e4f0974dbccd9771317a102533aa0df

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

LOG: [InstSimplify] Fold division by zero to poison

Div/rem by zero is immediate undefined behavior and anything goes.
Currently we fold it to undef, this patch changes it to fold to
poison instead, which is slightly stronger.

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

Added: 


Modified: 
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll
llvm/test/Transforms/InstCombine/div.ll
llvm/test/Transforms/InstCombine/icmp-div-constant.ll
llvm/test/Transforms/InstCombine/inselt-binop-inseltpoison.ll
llvm/test/Transforms/InstCombine/inselt-binop.ll
llvm/test/Transforms/InstCombine/rem.ll
llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll
llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll
llvm/test/Transforms/InstCombine/shift.ll
llvm/test/Transforms/InstCombine/vector-udiv.ll
llvm/test/Transforms/InstCombine/vector-urem.ll
llvm/test/Transforms/InstSimplify/div.ll
llvm/test/Transforms/InstSimplify/rem.ll
llvm/test/Transforms/InstSimplify/undef.ll
llvm/test/Transforms/SLPVectorizer/X86/alternate-int-inseltpoison.ll

Removed: 




diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp 
b/llvm/lib/Analysis/InstructionSimplify.cpp
index 4706969eafc0..0655374cbc1d 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -924,19 +924,19 @@ static Value *simplifyDivRem(Value *Op0, Value *Op1, bool 
IsDiv,
  const SimplifyQuery &Q) {
   Type *Ty = Op0->getType();
 
-  // X / undef -> undef
-  // X % undef -> undef
+  // X / undef -> poison
+  // X % undef -> poison
   if (Q.isUndefValue(Op1))
-return Op1;
+return PoisonValue::get(Ty);
 
-  // X / 0 -> undef
-  // X % 0 -> undef
+  // X / 0 -> poison
+  // X % 0 -> poison
   // We don't need to preserve faults!
   if (match(Op1, m_Zero()))
-return UndefValue::get(Ty);
+return PoisonValue::get(Ty);
 
-  // If any element of a constant divisor fixed width vector is zero or undef,
-  // the whole op is undef.
+  // If any element of a constant divisor fixed width vector is zero or undef
+  // the behavior is undefined and we can fold the whole op to poison.
   auto *Op1C = dyn_cast(Op1);
   auto *VTy = dyn_cast(Ty);
   if (Op1C && VTy) {
@@ -944,7 +944,7 @@ static Value *simplifyDivRem(Value *Op0, Value *Op1, bool 
IsDiv,
 for (unsigned i = 0; i != NumElts; ++i) {
   Constant *Elt = Op1C->getAggregateElement(i);
   if (Elt && (Elt->isNullValue() || Q.isUndefValue(Elt)))
-return UndefValue::get(Ty);
+return PoisonValue::get(Ty);
 }
   }
 

diff  --git a/llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll 
b/llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll
index 57a10c165f15..1dee5eb90ea1 100644
--- a/llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll
+++ b/llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll
@@ -212,7 +212,7 @@ define <2 x i64> @add-shl-sdiv-negative4(<2 x i64> %x) {
 
 define <3 x i8> @add-shl-sdiv-3xi8-undef0(<3 x i8> %x) {
 ; CHECK-LABEL: @add-shl-sdiv-3xi8-undef0(
-; CHECK-NEXT:ret <3 x i8> [[X:%.*]]
+; CHECK-NEXT:ret <3 x i8> poison
 ;
   %sd = sdiv <3 x i8> %x, 
   %sl = shl <3 x i8> %sd, 

diff  --git a/llvm/test/Transforms/InstCombine/div.ll 
b/llvm/test/Transforms/InstCombine/div.ll
index e06faf43348b..835db5e2c6ca 100644
--- a/llvm/test/Transforms/InstCombine/div.ll
+++ b/llvm/test/Transforms/InstCombine/div.ll
@@ -40,7 +40,7 @@ define <2 x i64> @sdiv_by_minus1_vec(<2 x i64> %x) {
 
 define <2 x i64> @sdiv_by_minus1_vec_undef_elt(<2 x i64> %x) {
 ; CHECK-LABEL: @sdiv_by_minus1_vec_undef_elt(
-; CHECK-NEXT:ret <2 x i64> undef
+; CHECK-NEXT:ret <2 x i64> poison
 ;
   %div = sdiv <2 x i64> %x, 
   ret <2 x i64> %div
@@ -514,7 +514,7 @@ define <2 x i8> 
@sdiv_negated_dividend_constant_divisor_vec_splat_smin(<2 x i8>
 
 define <2 x i8> @sdiv_negated_dividend_constant_divisor_vec_undef(<2 x i8> %x) 
{
 ; CHECK-LABEL: @sdiv_negated_dividend_constant_divisor_vec_undef(
-; CHECK-NEXT:ret <2 x i8> undef
+; CHECK-NEXT:ret <2 x i8> poison
 ;
   %neg = sub nsw <2 x i8> zeroinitializer, %x
   %d = sdiv <2 x i8> %neg, 
@@ -523,8 +523,8 @@ define <2 x i8> 
@sdiv_negated_dividend_constant_divisor_vec_undef(<2 x i8> %x) {
 
 define <2 x i64> @sdiv_negated_dividend_constant_divisor_vec(<2 x i64> %x) {
 ; CHECK-LABEL: @sdiv_negated_dividend_constant_divisor_vec(
-; CHECK-NEXT:[[DIV:%.*]] = sdiv <2 x i64> [[X:%.*]], 
-; CHECK-NEXT:ret <2 x i64> [[DIV]]
+; CH

[llvm-branch-commits] [llvm] edb52c6 - [LoopUnswitch] Precommit initial partial unswitching test cases.

2021-01-03 Thread Florian Hahn via llvm-branch-commits

Author: Florian Hahn
Date: 2021-01-03T20:34:32Z
New Revision: edb52c626b5340a5a42ed833fc776bc815507283

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

LOG: [LoopUnswitch] Precommit initial partial unswitching test cases.

Added: 
llvm/test/Transforms/LoopUnswitch/partial-unswitch.ll

Modified: 


Removed: 




diff  --git a/llvm/test/Transforms/LoopUnswitch/partial-unswitch.ll 
b/llvm/test/Transforms/LoopUnswitch/partial-unswitch.ll
new file mode 100644
index ..742e35a99b5d
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnswitch/partial-unswitch.ll
@@ -0,0 +1,461 @@
+; RUN: opt -loop-unswitch -verify-dom-info -verify-memoryssa -S %s | FileCheck 
%s
+
+declare void @clobber()
+
+define i32 @partial_unswitch_true_successor(i32* %ptr, i32 %N) {
+; CHECK-LABEL: @partial_unswitch_true_successor
+; CHECK-LABEL: entry:
+; CHECK-NEXT:br label %loop.header
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  %lv = load i32, i32* %ptr
+  %sc = icmp eq i32 %lv, 100
+  br i1 %sc, label %noclobber, label %clobber
+
+noclobber:
+  br label %loop.latch
+
+clobber:
+  call void @clobber()
+  br label %loop.latch
+
+loop.latch:
+  %c = icmp ult i32 %iv, %N
+  %iv.next = add i32 %iv, 1
+  br i1 %c, label %loop.header, label %exit
+
+exit:
+  ret i32 10
+}
+
+define i32 @partial_unswitch_false_successor(i32* %ptr, i32 %N) {
+; CHECK-LABEL: @partial_unswitch_false_successor
+; CHECK-LABEL: entry:
+; CHECK-NEXT:br label %loop.header
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  %lv = load i32, i32* %ptr
+  %sc = icmp eq i32 %lv, 100
+  br i1 %sc, label %clobber, label %noclobber
+
+clobber:
+  call void @clobber()
+  br label %loop.latch
+
+noclobber:
+  br label %loop.latch
+
+loop.latch:
+  %c = icmp ult i32 %iv, %N
+  %iv.next = add i32 %iv, 1
+  br i1 %c, label %loop.header, label %exit
+
+exit:
+  ret i32 10
+}
+
+define i32 @partial_unswtich_gep_load_icmp(i32** %ptr, i32 %N) {
+; CHECK-LABEL: @partial_unswtich_gep_load_icmp
+; CHECK-LABEL: entry:
+; CHECK-NEXT:br label %loop.header
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  %gep = getelementptr i32*, i32** %ptr, i32 1
+  %lv.1 = load i32*, i32** %gep
+  %lv = load i32, i32* %lv.1
+  %sc = icmp eq i32 %lv, 100
+  br i1 %sc, label %noclobber, label %clobber
+
+noclobber:
+  br label %loop.latch
+
+clobber:
+  call void @clobber()
+  br label %loop.latch
+
+loop.latch:
+  %c = icmp ult i32 %iv, %N
+  %iv.next = add i32 %iv, 1
+  br i1 %c, label %loop.header, label %exit
+
+exit:
+  ret i32 10
+}
+
+define i32 @partial_unswitch_reduction_phi(i32* %ptr, i32 %N) {
+; CHECK-LABEL: @partial_unswitch_reduction_phi
+; CHECK-LABEL: entry:
+; CHECK-NEXT:br label %loop.header
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  %red = phi i32 [ 20, %entry ], [ %red.next, %loop.latch ]
+  %lv = load i32, i32* %ptr
+  %sc = icmp eq i32 %lv, 100
+  br i1 %sc, label %clobber, label %noclobber
+
+clobber:
+  call void @clobber()
+  %add.5 = add i32 %red, 5
+  br label %loop.latch
+
+noclobber:
+  %add.10 = add i32 %red, 10
+  br label %loop.latch
+
+loop.latch:
+  %red.next = phi i32 [ %add.5, %clobber ], [ %add.10, %noclobber ]
+  %c = icmp ult i32 %iv, %N
+  %iv.next = add i32 %iv, 1
+  br i1 %c, label %loop.header, label %exit
+
+exit:
+  %red.next.lcssa = phi i32 [ %red.next, %loop.latch ]
+  ret i32 %red.next.lcssa
+}
+
+; Partial unswitching is possible, because the store in %noclobber does not
+; alias the load of the condition.
+define i32 @partial_unswitch_true_successor_noclobber(i32* noalias %ptr.1, 
i32* noalias %ptr.2, i32 %N) {
+; CHECK-LABEL: @partial_unswitch_true_successor
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:br label %loop.header
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  %lv = load i32, i32* %ptr.1
+  %sc = icmp eq i32 %lv, 100
+  br i1 %sc, label %noclobber, label %clobber
+
+noclobber:
+  %gep.1 = getelementptr i32, i32* %ptr.2, i32 %iv
+  store i32 %lv, i32* %gep.1
+  br label %loop.latch
+
+clobber:
+  call void @clobber()
+  br label %loop.latch
+
+loop.latch:
+  %c = icmp ult i32 %iv, %N
+  %iv.next = add i32 %iv, 1
+  br i1 %c, label %loop.header, label %exit
+
+exit:
+  ret i32 10
+}
+
+define void @no_partial_unswitch_phi_cond(i1 %lc, i32 %N) {
+; CHECK-LABEL: @no_partial_unswitch_phi_cond
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:br label %loop.header
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  %sc = phi i1 [ %lc

[llvm-branch-commits] [llvm] 3715c99 - [InstSimplify] Fold nnan/ninf violation to poison

2021-01-03 Thread Nikita Popov via llvm-branch-commits

Author: Nikita Popov
Date: 2021-01-03T22:05:40+01:00
New Revision: 3715c99be9dcde1421f2365a59ab2bc433993d7c

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

LOG: [InstSimplify] Fold nnan/ninf violation to poison

As the comment already indicates, performing an operation with
nnan/ninf flags on a nan/inf or undef results in poison. Now that
we have a proper poison value, we no longer need to relax it to
undef.

Added: 


Modified: 
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/fp-nan.ll
llvm/test/Transforms/InstSimplify/fp-undef-poison.ll

Removed: 




diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp 
b/llvm/lib/Analysis/InstructionSimplify.cpp
index 0655374cbc1dd..d89a776b7908b 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4781,11 +4781,11 @@ static Constant *simplifyFPOp(ArrayRef Ops,
 
 // If this operation has 'nnan' or 'ninf' and at least 1 disallowed operand
 // (an undef operand can be chosen to be Nan/Inf), then the result of
-// this operation is poison. That result can be relaxed to undef.
+// this operation is poison.
 if (FMF.noNaNs() && (IsNan || IsUndef))
-  return UndefValue::get(V->getType());
+  return PoisonValue::get(V->getType());
 if (FMF.noInfs() && (IsInf || IsUndef))
-  return UndefValue::get(V->getType());
+  return PoisonValue::get(V->getType());
 
 if (IsUndef || IsNan)
   return propagateNaN(cast(V));

diff  --git a/llvm/test/Transforms/InstSimplify/fp-nan.ll 
b/llvm/test/Transforms/InstSimplify/fp-nan.ll
index 7382fdfbe1a25..4cce3be002e9e 100644
--- a/llvm/test/Transforms/InstSimplify/fp-nan.ll
+++ b/llvm/test/Transforms/InstSimplify/fp-nan.ll
@@ -137,7 +137,7 @@ define <2 x double> @unary_fneg_nan_2(<2 x double> %x) {
 
 define float @fadd_nan_op0_nnan(float %x) {
 ; CHECK-LABEL: @fadd_nan_op0_nnan(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = fadd nnan float 0x7FF8, %x
   ret float %r
@@ -145,7 +145,7 @@ define float @fadd_nan_op0_nnan(float %x) {
 
 define float @fadd_nan_op1_fast(float %x) {
 ; CHECK-LABEL: @fadd_nan_op1_fast(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = fadd fast float %x, 0x7FF8
   ret float %r
@@ -153,7 +153,7 @@ define float @fadd_nan_op1_fast(float %x) {
 
 define float @fsub_nan_op0_fast(float %x) {
 ; CHECK-LABEL: @fsub_nan_op0_fast(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = fsub fast float 0x7FF8, %x
   ret float %r
@@ -161,7 +161,7 @@ define float @fsub_nan_op0_fast(float %x) {
 
 define float @fsub_nan_op1_nnan(float %x) {
 ; CHECK-LABEL: @fsub_nan_op1_nnan(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = fsub nnan float %x, 0x7FF8
   ret float %r
@@ -169,7 +169,7 @@ define float @fsub_nan_op1_nnan(float %x) {
 
 define float @fmul_nan_op0_nnan(float %x) {
 ; CHECK-LABEL: @fmul_nan_op0_nnan(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = fmul nnan float 0x7FF8, %x
   ret float %r
@@ -177,7 +177,7 @@ define float @fmul_nan_op0_nnan(float %x) {
 
 define float @fmul_nan_op1_fast(float %x) {
 ; CHECK-LABEL: @fmul_nan_op1_fast(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = fmul fast float %x, 0x7FF8
   ret float %r
@@ -185,7 +185,7 @@ define float @fmul_nan_op1_fast(float %x) {
 
 define float @fdiv_nan_op0_fast(float %x) {
 ; CHECK-LABEL: @fdiv_nan_op0_fast(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = fdiv fast float 0x7FF8, %x
   ret float %r
@@ -193,7 +193,7 @@ define float @fdiv_nan_op0_fast(float %x) {
 
 define float @fdiv_nan_op1_nnan(float %x) {
 ; CHECK-LABEL: @fdiv_nan_op1_nnan(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = fdiv nnan float %x, 0x7FF8
   ret float %r
@@ -201,7 +201,7 @@ define float @fdiv_nan_op1_nnan(float %x) {
 
 define float @frem_nan_op0_nnan(float %x) {
 ; CHECK-LABEL: @frem_nan_op0_nnan(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = frem nnan float 0x7FF8, %x
   ret float %r
@@ -209,7 +209,7 @@ define float @frem_nan_op0_nnan(float %x) {
 
 define float @frem_nan_op1_fast(float %x) {
 ; CHECK-LABEL: @frem_nan_op1_fast(
-; CHECK-NEXT:ret float undef
+; CHECK-NEXT:ret float poison
 ;
   %r = frem fast float %x, 0x7FF8
   ret float %r

diff  --git a/llvm/test/Transforms/InstSimplify/fp-undef-poison.ll 
b/llvm/test/Transforms/InstSimplify/fp-undef-poison.ll
index 696dc84bd4ce2..129d868704c46 100644
--- a/llvm/te

[llvm-branch-commits] [llvm] 4fc9080 - [NFC][SimplifyCFG] Add a test where we fail to preserve DomTree validity

2021-01-03 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-04T01:02:01+03:00
New Revision: 4fc908025fd003a7517e392f35389364fb60500d

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

LOG: [NFC][SimplifyCFG] Add a test where we fail to preserve DomTree validity

Added: 

llvm/test/Transforms/SimplifyCFG/SimplifyTerminatorOnSelect-domtree-preservation-edgecase.ll

Modified: 


Removed: 




diff  --git 
a/llvm/test/Transforms/SimplifyCFG/SimplifyTerminatorOnSelect-domtree-preservation-edgecase.ll
 
b/llvm/test/Transforms/SimplifyCFG/SimplifyTerminatorOnSelect-domtree-preservation-edgecase.ll
new file mode 100644
index ..752de63c2933
--- /dev/null
+++ 
b/llvm/test/Transforms/SimplifyCFG/SimplifyTerminatorOnSelect-domtree-preservation-edgecase.ll
@@ -0,0 +1,58 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=0 < %s | 
FileCheck %s
+
+declare void @widget()
+declare void @baz(i8)
+declare void @snork()
+declare void @spam(i8)
+declare void @zot()
+
+define void @wombat(i64 %arg, i1 %arg1) {
+; CHECK-LABEL: @wombat(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:[[COND:%.*]] = icmp eq i64 [[ARG:%.*]], 0
+; CHECK-NEXT:br i1 [[COND]], label [[BB4:%.*]], label [[BB2:%.*]]
+; CHECK:   bb2:
+; CHECK-NEXT:call void @widget()
+; CHECK-NEXT:br label [[BB4]]
+; CHECK:   bb4:
+; CHECK-NEXT:[[TMP:%.*]] = phi i8 [ 0, [[BB:%.*]] ], [ 1, [[BB2]] ]
+; CHECK-NEXT:call void @baz(i8 [[TMP]])
+; CHECK-NEXT:call void @snork()
+; CHECK-NEXT:call void @spam(i8 4)
+; CHECK-NEXT:ret void
+;
+bb:
+  switch i64 %arg, label %bb2 [
+  i64 0, label %bb3
+  ]
+
+bb2:  ; preds = %bb
+  call void @widget()
+  br label %bb3
+
+bb3:  ; preds = %bb2, %bb
+  %tmp = phi i8 [ 0, %bb ], [ 1, %bb2 ]
+  br label %bb4
+
+bb4:  ; preds = %bb3
+  call void @baz(i8 %tmp)
+  %tmp5 = select i1 %arg1, i64 6, i64 3
+  switch i64 %tmp5, label %bb7 [
+  i64 1, label %bb6
+  i64 0, label %bb8
+  ]
+
+bb6:  ; preds = %bb4
+  call void @zot()
+  br label %bb8
+
+bb7:  ; preds = %bb4
+  call void @snork()
+  br label %bb8
+
+bb8:  ; preds = %bb7, %bb6, %bb4
+  %tmp9 = phi i8 [ 2, %bb4 ], [ 3, %bb6 ], [ 4, %bb7 ]
+  call void @spam(i8 %tmp9)
+  ret void
+}



___
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] 70935b9 - [NFC][SimplifyCFG] SimplifyTerminatorOnSelect(): pull out OldTerm->getParent() into a variable

2021-01-03 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-04T01:02:02+03:00
New Revision: 70935b9595a410794882d043726a1aad38d44ebd

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

LOG: [NFC][SimplifyCFG] SimplifyTerminatorOnSelect(): pull out 
OldTerm->getParent() into a variable

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index d581c97f9fea..d4f77757a290 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3848,6 +3848,8 @@ bool 
SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
 BasicBlock *FalseBB,
 uint32_t TrueWeight,
 uint32_t FalseWeight) {
+  auto *BB = OldTerm->getParent();
+
   // Remove any superfluous successor edges from the CFG.
   // First, figure out which successors to preserve.
   // If TrueBB and FalseBB are equal, only try to preserve one copy of that
@@ -3865,9 +3867,9 @@ bool 
SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
 else if (Succ == KeepEdge2)
   KeepEdge2 = nullptr;
 else {
-  Succ->removePredecessor(OldTerm->getParent(),
+  Succ->removePredecessor(BB,
   /*KeepOneInputPHIs=*/true);
-  Updates.push_back({DominatorTree::Delete, OldTerm->getParent(), Succ});
+  Updates.push_back({DominatorTree::Delete, BB, Succ});
 }
   }
 
@@ -3880,13 +3882,13 @@ bool 
SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
   // We were only looking for one successor, and it was present.
   // Create an unconditional branch to it.
   Builder.CreateBr(TrueBB);
-  Updates.push_back({DominatorTree::Insert, OldTerm->getParent(), TrueBB});
+  Updates.push_back({DominatorTree::Insert, BB, TrueBB});
 } else {
   // We found both of the successors we were looking for.
   // Create a conditional branch sharing the condition of the select.
   BranchInst *NewBI = Builder.CreateCondBr(Cond, TrueBB, FalseBB);
-  Updates.push_back({DominatorTree::Insert, OldTerm->getParent(), TrueBB});
-  Updates.push_back({DominatorTree::Insert, OldTerm->getParent(), 
FalseBB});
+  Updates.push_back({DominatorTree::Insert, BB, TrueBB});
+  Updates.push_back({DominatorTree::Insert, BB, FalseBB});
   if (TrueWeight != FalseWeight)
 setBranchWeights(NewBI, TrueWeight, FalseWeight);
 }
@@ -3901,11 +3903,11 @@ bool 
SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
 if (!KeepEdge1) {
   // Only TrueBB was found.
   Builder.CreateBr(TrueBB);
-  Updates.push_back({DominatorTree::Insert, OldTerm->getParent(), TrueBB});
+  Updates.push_back({DominatorTree::Insert, BB, TrueBB});
 } else {
   // Only FalseBB was found.
   Builder.CreateBr(FalseBB);
-  Updates.push_back({DominatorTree::Insert, OldTerm->getParent(), 
FalseBB});
+  Updates.push_back({DominatorTree::Insert, BB, FalseBB});
 }
   }
 



___
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] a768494 - [SimplifyCFG] SimplifyTerminatorOnSelect(): fix/tune DomTree updates

2021-01-03 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-04T01:02:02+03:00
New Revision: a7684940f0e4eafb1bafc75cfb0e620ee358abd4

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

LOG: [SimplifyCFG] SimplifyTerminatorOnSelect(): fix/tune DomTree updates

We only need to remove non-TrueBB/non-FalseBB successors,
and we only need to do that once. We don't need to insert
any new edges, because no new successors will be added.

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp

llvm/test/Transforms/SimplifyCFG/SimplifyTerminatorOnSelect-domtree-preservation-edgecase.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index d4f77757a290..f02ff2252f7d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3849,7 +3849,6 @@ bool 
SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
 uint32_t TrueWeight,
 uint32_t FalseWeight) {
   auto *BB = OldTerm->getParent();
-
   // Remove any superfluous successor edges from the CFG.
   // First, figure out which successors to preserve.
   // If TrueBB and FalseBB are equal, only try to preserve one copy of that
@@ -3857,7 +3856,7 @@ bool 
SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
   BasicBlock *KeepEdge1 = TrueBB;
   BasicBlock *KeepEdge2 = TrueBB != FalseBB ? FalseBB : nullptr;
 
-  SmallVector Updates;
+  SmallSetVector RemovedSuccessors;
 
   // Then remove the rest.
   for (BasicBlock *Succ : successors(OldTerm)) {
@@ -3869,7 +3868,9 @@ bool 
SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
 else {
   Succ->removePredecessor(BB,
   /*KeepOneInputPHIs=*/true);
-  Updates.push_back({DominatorTree::Delete, BB, Succ});
+
+  if (Succ != TrueBB && Succ != FalseBB)
+RemovedSuccessors.insert(Succ);
 }
   }
 
@@ -3882,13 +3883,10 @@ bool 
SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
   // We were only looking for one successor, and it was present.
   // Create an unconditional branch to it.
   Builder.CreateBr(TrueBB);
-  Updates.push_back({DominatorTree::Insert, BB, TrueBB});
 } else {
   // We found both of the successors we were looking for.
   // Create a conditional branch sharing the condition of the select.
   BranchInst *NewBI = Builder.CreateCondBr(Cond, TrueBB, FalseBB);
-  Updates.push_back({DominatorTree::Insert, BB, TrueBB});
-  Updates.push_back({DominatorTree::Insert, BB, FalseBB});
   if (TrueWeight != FalseWeight)
 setBranchWeights(NewBI, TrueWeight, FalseWeight);
 }
@@ -3903,17 +3901,22 @@ bool 
SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
 if (!KeepEdge1) {
   // Only TrueBB was found.
   Builder.CreateBr(TrueBB);
-  Updates.push_back({DominatorTree::Insert, BB, TrueBB});
 } else {
   // Only FalseBB was found.
   Builder.CreateBr(FalseBB);
-  Updates.push_back({DominatorTree::Insert, BB, FalseBB});
 }
   }
 
   EraseTerminatorAndDCECond(OldTerm);
-  if (DTU)
-DTU->applyUpdatesPermissive(Updates);
+
+  if (DTU) {
+SmallVector Updates;
+Updates.reserve(RemovedSuccessors.size());
+for (auto *RemovedSuccessor : RemovedSuccessors)
+  Updates.push_back({DominatorTree::Delete, BB, RemovedSuccessor});
+DTU->applyUpdates(Updates);
+  }
+
   return true;
 }
 

diff  --git 
a/llvm/test/Transforms/SimplifyCFG/SimplifyTerminatorOnSelect-domtree-preservation-edgecase.ll
 
b/llvm/test/Transforms/SimplifyCFG/SimplifyTerminatorOnSelect-domtree-preservation-edgecase.ll
index 752de63c2933..792a1a534a93 100644
--- 
a/llvm/test/Transforms/SimplifyCFG/SimplifyTerminatorOnSelect-domtree-preservation-edgecase.ll
+++ 
b/llvm/test/Transforms/SimplifyCFG/SimplifyTerminatorOnSelect-domtree-preservation-edgecase.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=0 < %s | 
FileCheck %s
+; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | 
FileCheck %s
 
 declare void @widget()
 declare void @baz(i8)



___
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] 98cd1c3 - [NFC][SimplifyCFG] Hoist 'original' DomTree verification from simplifyOnce() into run()

2021-01-03 Thread Roman Lebedev via llvm-branch-commits

Author: Roman Lebedev
Date: 2021-01-04T01:02:02+03:00
New Revision: 98cd1c33e3c2c3cfee36fb0fea3285fda06224d3

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

LOG: [NFC][SimplifyCFG] Hoist 'original' DomTree verification from 
simplifyOnce() into run()

This is NFC since SimplifyCFG still currently defaults to not preserving 
DomTree.

SimplifyCFGOpt::simplifyOnce() is only be called from SimplifyCFGOpt::run(),
and can not be called externally, since SimplifyCFGOpt is defined in .cpp
This avoids some needless verifications, and is thus a bit faster
without sacrificing precision.

Added: 


Modified: 
llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 




diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index f02ff2252f7d..a4faf22b8294 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6675,11 +6675,6 @@ bool SimplifyCFGOpt::simplifyOnceImpl(BasicBlock *BB) {
 }
 
 bool SimplifyCFGOpt::simplifyOnce(BasicBlock *BB) {
-  assert((!RequireAndPreserveDomTree ||
-  (DTU &&
-   DTU->getDomTree().verify(DominatorTree::VerificationLevel::Full))) 
&&
- "Original domtree is invalid?");
-
   bool Changed = simplifyOnceImpl(BB);
 
   assert((!RequireAndPreserveDomTree ||
@@ -6691,6 +6686,11 @@ bool SimplifyCFGOpt::simplifyOnce(BasicBlock *BB) {
 }
 
 bool SimplifyCFGOpt::run(BasicBlock *BB) {
+  assert((!RequireAndPreserveDomTree ||
+  (DTU &&
+   DTU->getDomTree().verify(DominatorTree::VerificationLevel::Full))) 
&&
+ "Original domtree is invalid?");
+
   bool Changed = false;
 
   // Repeated simplify BB as long as resimplification is requested.



___
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] [compiler-rt] 3f0c4bf - [NFC][sanitizer] Fix ppc -> powerpc64 in XFAIL

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-01T17:57:42-08:00
New Revision: 3f0c4bfc64f377e6d67db713b3bd4defb495610a

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

LOG: [NFC][sanitizer] Fix ppc -> powerpc64 in XFAIL

Added: 


Modified: 
compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp

Removed: 




diff  --git 
a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
index 29b9ae53b2bd..fd8f73ca713b 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
@@ -9,7 +9,7 @@
 // UNSUPPORTED: lsan, ubsan, android
 
 // FIXME: Investigate
-// XFAIL: ppc && tsan
+// XFAIL: powerpc64 && tsan
 
 #include 
 



___
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] [compiler-rt] bdd6718 - [NFC] Disable new test from D92428 on PPC TSAN

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-01T16:54:14-08:00
New Revision: bdd6718bef6f2b1f74c346b239debd6c511e4265

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

LOG: [NFC] Disable new test from D92428 on PPC TSAN

Added: 


Modified: 
compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp

Removed: 




diff  --git 
a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
index 8330384a305a..29b9ae53b2bd 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
@@ -8,6 +8,9 @@
 // Do not intercept __tls_get_addr
 // UNSUPPORTED: lsan, ubsan, android
 
+// FIXME: Investigate
+// XFAIL: ppc && tsan
+
 #include 
 
 #ifndef BUILD_DSO



___
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] [compiler-rt] b4655a0 - [NFC][sanitizer] Remove unused typedef

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-28T13:17:07-08:00
New Revision: b4655a0815d0cd75297cfe323526397ee7a03dca

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

LOG: [NFC][sanitizer] Remove unused typedef

Added: 


Modified: 
compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h

Removed: 




diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
index 0350fe84b045..15616f899d01 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
@@ -67,8 +67,6 @@ struct StackTrace {
   static uptr GetCurrentPc();
   static inline uptr GetPreviousInstructionPc(uptr pc);
   static uptr GetNextInstructionPc(uptr pc);
-  typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer,
-int out_size);
 };
 
 // Performance-critical, must be in the header.



___
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] 1f21f6d - [NFC][CodeGen] Simplify SanitizeDtorMembers::Emit

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-05T21:11:27-08:00
New Revision: 1f21f6d6a4cef3dd7cb169e1071ee372c2efe1a7

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

LOG: [NFC][CodeGen] Simplify SanitizeDtorMembers::Emit

Added: 


Modified: 
clang/lib/CodeGen/CGClass.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 5bd484eb1464..0d17037db864 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1693,28 +1693,22 @@ namespace {
   // Construct pointer to region to begin poisoning, and calculate poison
   // size, so that only members declared in this class are poisoned.
   ASTContext &Context = CGF.getContext();
-  unsigned fieldIndex = 0;
-  int startIndex = -1;
-  // RecordDecl::field_iterator Field;
-  for (const FieldDecl *Field : Dtor->getParent()->fields()) {
-// Poison field if it is trivial
-if (FieldHasTrivialDestructorBody(Context, Field)) {
-  // Start sanitizing at this field
-  if (startIndex < 0)
-startIndex = fieldIndex;
-
-  // Currently on the last field, and it must be poisoned with the
-  // current block.
-  if (fieldIndex == Layout.getFieldCount() - 1) {
-PoisonMembers(CGF, startIndex, Layout.getFieldCount());
-  }
-} else if (startIndex >= 0) {
-  // No longer within a block of memory to poison, so poison the block
-  PoisonMembers(CGF, startIndex, fieldIndex);
-  // Re-set the start index
-  startIndex = -1;
-}
-fieldIndex += 1;
+
+  const RecordDecl *Decl = Dtor->getParent();
+  auto Fields = Decl->fields();
+  auto IsTrivial = [&](const FieldDecl *F) {
+return FieldHasTrivialDestructorBody(Context, F);
+  };
+
+  for (auto It = Fields.begin(); It != Fields.end();) {
+It = std::find_if(It, Fields.end(), IsTrivial);
+if (It == Fields.end())
+  break;
+auto Start = It++;
+It = std::find_if_not(It, Fields.end(), IsTrivial);
+
+PoisonMembers(CGF, (*Start)->getFieldIndex(),
+  It == Fields.end() ? -1 : (*It)->getFieldIndex());
   }
 }
 



___
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] [compiler-rt] 1f3def1 - [NFC][sanitizer] Fix test on 32bit platform

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-02T07:32:40-08:00
New Revision: 1f3def16f6e563a16a0c17d1c251d47cd57a691a

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

LOG: [NFC][sanitizer] Fix test on 32bit platform

Added: 


Modified: 
compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp

Removed: 




diff  --git 
a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
index 11c0e48a855e..d126d79e8afe 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
@@ -53,6 +53,5 @@ extern "C" void StoreToTLS(char c) {
 
 // CHECK:  DTLS_Find [[DTLS:0x[a-f0-9]+]] {{[0-9]+}}
 // CHECK-NEXT: DTLS_NextBlock [[DTLS]] 0
-// CHECK:  DTLS_Find [[DTLS:0x[a-f0-9]+]] 255
+// CHECK:  DTLS_Find [[DTLS:0x[a-f0-9]+]] {{255|511}}
 // CHECK-NEXT: DTLS_NextBlock [[DTLS]] 1
-// CHECK-NOT:  DTLS_NextBlock



___
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] [compiler-rt] 20a2b1b - [NFC][sanitizer] Another attempt to fix test on arm

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-02T18:36:02-08:00
New Revision: 20a2b1bf6bfec9a90e56cecd79d918bd5c0f6cc6

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

LOG: [NFC][sanitizer] Another attempt to fix test on arm

Added: 


Modified: 
compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp

Removed: 




diff  --git 
a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp 
b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
index d126d79e8afe..5ebf98c955c9 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
@@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {
   system(buff);
 
   void *prev_handle = 0;
-  for (int i = 0; i < 300; ++i) {
+  for (int i = 0; i < 600; ++i) {
 sprintf(buff, "cp %s.so %s.so.%d", argv[0], argv[0], i);
 system(buff);
 
@@ -51,7 +51,7 @@ extern "C" void StoreToTLS(char c) {
 }
 #endif // BUILD_DSO
 
-// CHECK:  DTLS_Find [[DTLS:0x[a-f0-9]+]] {{[0-9]+}}
-// CHECK-NEXT: DTLS_NextBlock [[DTLS]] 0
-// CHECK:  DTLS_Find [[DTLS:0x[a-f0-9]+]] {{255|511}}
-// CHECK-NEXT: DTLS_NextBlock [[DTLS]] 1
+// CHECK: DTLS_Find [[DTLS:0x[a-f0-9]+]] {{[0-9]+}}
+// CHECK: DTLS_NextBlock [[DTLS]] 0
+// CHECK: DTLS_Find [[DTLS:0x[a-f0-9]+]] {{[0-9]+}}
+// CHECK: DTLS_NextBlock [[DTLS]] 1



___
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] [compiler-rt] 4e74480 - [NFC][sanitizer] Simplify InternalLowerBound

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-29T14:01:43-08:00
New Revision: 4e74480e0234f27f40e26dec085b2a9eb2149578

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

LOG: [NFC][sanitizer] Simplify InternalLowerBound

Added: 


Modified: 
compiler-rt/lib/lsan/lsan_common.cpp
compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
compiler-rt/lib/sanitizer_common/sanitizer_common.h
compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp

Removed: 




diff  --git a/compiler-rt/lib/lsan/lsan_common.cpp 
b/compiler-rt/lib/lsan/lsan_common.cpp
index 30c154a4fc94..ddedfa0830e1 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -551,8 +551,7 @@ static void ReportIfNotSuspended(ThreadContextBase *tctx, 
void *arg) {
   const InternalMmapVector &suspended_threads =
   *(const InternalMmapVector *)arg;
   if (tctx->status == ThreadStatusRunning) {
-uptr i = InternalLowerBound(suspended_threads, 0, suspended_threads.size(),
-tctx->os_id, CompareLess());
+uptr i = InternalLowerBound(suspended_threads, tctx->os_id);
 if (i >= suspended_threads.size() || suspended_threads[i] != tctx->os_id)
   Report("Running thread %d was not suspended. False leaks are 
possible.\n",
  tctx->os_id);

diff  --git a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp 
b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
index 3c62c9433d3d..2d35fa5b1cff 100644
--- a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
+++ b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
@@ -107,9 +107,7 @@ void LockStuffAndStopTheWorld(StopTheWorldCallback callback,
 auto params = static_cast(data);
 uptr begin = reinterpret_cast(chunk);
 uptr end = begin + size;
-auto i = __sanitizer::InternalLowerBound(params->allocator_caches, 0,
- params->allocator_caches.size(),
- begin, CompareLess());
+auto i = __sanitizer::InternalLowerBound(params->allocator_caches, begin);
 if (i < params->allocator_caches.size() &&
 params->allocator_caches[i] >= begin &&
 end - params->allocator_caches[i] <= sizeof(AllocatorCache)) {

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index bce24d68045b..60d1c62b0681 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -467,6 +467,7 @@ inline int ToLower(int c) {
 template
 class InternalMmapVectorNoCtor {
  public:
+  using value_type = T;
   void Initialize(uptr initial_capacity) {
 capacity_bytes_ = 0;
 size_ = 0;
@@ -651,9 +652,13 @@ void Sort(T *v, uptr size, Compare comp = {}) {
 
 // Works like std::lower_bound: finds the first element that is not less
 // than the val.
-template 
-uptr InternalLowerBound(const Container &v, uptr first, uptr last,
-const Value &val, Compare comp) {
+template >
+uptr InternalLowerBound(const Container &v,
+const typename Container::value_type &val,
+Compare comp = {}) {
+  uptr first = 0;
+  uptr last = v.size();
   while (last > first) {
 uptr mid = (first + last) / 2;
 if (comp(v[mid], val))

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
index 4692f50d3237..44a95214e38b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
@@ -145,8 +145,7 @@ StackTrace StackDepotReverseMap::Get(u32 id) {
   if (!map_.size())
 return StackTrace();
   IdDescPair pair = {id, nullptr};
-  uptr idx =
-  InternalLowerBound(map_, 0, map_.size(), pair, IdDescPair::IdComparator);
+  uptr idx = InternalLowerBound(map_, pair, IdDescPair::IdComparator);
   if (idx > map_.size() || map_[idx].id != id)
 return StackTrace();
   return map_[idx].desc->load();

diff  --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp 
b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp
index 259bd99324a2..1d0806c4c404 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp
@@ -226,27 +226,21 @@ bool UptrLess(uptr a, uptr b) {
 }
 
 TEST(SanitizerCommon, InternalLowerBound) {
-  static const uptr kSize = 5;
-  int arr[kSize];
-  arr[0] = 1;
-  arr[1] = 3;
-  arr[2] = 5;
-  arr[3] = 7;
-  arr[4] = 11;
-
-  EXPECT_EQ(0u, InternalLowerBound(arr, 0, kSize, 0, UptrLess));
-  EXPECT_EQ(0u, InternalLowerBound(ar

[llvm-branch-commits] [compiler-rt] 673b12e - [tsan] Remove stdlib.h from dd_interceptors.cpp

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-29T14:00:54-08:00
New Revision: 673b12e76ff7a6941be35cf41dcb04a015acf51f

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

LOG: [tsan] Remove stdlib.h from dd_interceptors.cpp

This fixes "realpath already defined" error.

Reviewed By: eugenis

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

Added: 


Modified: 
compiler-rt/lib/tsan/dd/dd_interceptors.cpp

Removed: 




diff  --git a/compiler-rt/lib/tsan/dd/dd_interceptors.cpp 
b/compiler-rt/lib/tsan/dd/dd_interceptors.cpp
index 35a0beb19196..f78ef2d44279 100644
--- a/compiler-rt/lib/tsan/dd/dd_interceptors.cpp
+++ b/compiler-rt/lib/tsan/dd/dd_interceptors.cpp
@@ -6,11 +6,12 @@
 //
 
//===--===//
 
+#include 
+
 #include "dd_rtl.h"
 #include "interception/interception.h"
+#include "sanitizer_common/sanitizer_allocator_internal.h"
 #include "sanitizer_common/sanitizer_procmaps.h"
-#include 
-#include 
 
 using namespace __dsan;
 
@@ -163,12 +164,12 @@ static pthread_cond_t *init_cond(pthread_cond_t *c, bool 
force = false) {
   uptr cond = atomic_load(p, memory_order_acquire);
   if (!force && cond != 0)
 return (pthread_cond_t*)cond;
-  void *newcond = malloc(sizeof(pthread_cond_t));
+  void *newcond = InternalAlloc(sizeof(pthread_cond_t));
   internal_memset(newcond, 0, sizeof(pthread_cond_t));
   if (atomic_compare_exchange_strong(p, &cond, (uptr)newcond,
   memory_order_acq_rel))
 return (pthread_cond_t*)newcond;
-  free(newcond);
+  InternalFree(newcond);
   return (pthread_cond_t*)cond;
 }
 
@@ -216,7 +217,7 @@ INTERCEPTOR(int, pthread_cond_destroy, pthread_cond_t *c) {
   InitThread();
   pthread_cond_t *cond = init_cond(c);
   int res = REAL(pthread_cond_destroy)(cond);
-  free(cond);
+  InternalFree(cond);
   atomic_store((atomic_uintptr_t*)c, 0, memory_order_relaxed);
   return res;
 }



___
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] [compiler-rt] 3c0d36f - [NFC][lsan] Add nested leak in test

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-29T14:01:43-08:00
New Revision: 3c0d36f977d9e012b245c796ddc8596ac3af659b

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

LOG: [NFC][lsan] Add nested leak in test

Added: 


Modified: 
compiler-rt/test/lsan/TestCases/suppressions_file.cpp

Removed: 




diff  --git a/compiler-rt/test/lsan/TestCases/suppressions_file.cpp 
b/compiler-rt/test/lsan/TestCases/suppressions_file.cpp
index 29422bd3c2c0..2983c16e2c8a 100644
--- a/compiler-rt/test/lsan/TestCases/suppressions_file.cpp
+++ b/compiler-rt/test/lsan/TestCases/suppressions_file.cpp
@@ -17,19 +17,27 @@
 #include 
 #include 
 
-void LSanTestLeakingFunc() {
+void* LSanTestLeakingFunc() {
   void *p = malloc(666);
   fprintf(stderr, "Test alloc: %p.\n", p);
+  return p;
+}
+
+void LSanTestUnsuppressedLeakingFunc() {
+  void** p = (void**)LSanTestLeakingFunc();
+  // FIXME: This must be suppressed as well.
+  *p = malloc(777);
+  fprintf(stderr, "Test alloc: %p.\n", *p);
 }
 
 int main() {
-  LSanTestLeakingFunc();
+  LSanTestUnsuppressedLeakingFunc();
   void *q = malloc(1337);
   fprintf(stderr, "Test alloc: %p.\n", q);
   return 0;
 }
 // CHECK: Suppressions used:
 // CHECK: 1 666 *LSanTestLeakingFunc*
-// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 
allocation(s)
+// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 2114 byte(s) leaked in 2 
allocation(s)
 
-// NOSUPP: SUMMARY: {{(Leak|Address)}}Sanitizer: 2003 byte(s) leaked in 2 
allocation(s).
+// NOSUPP: SUMMARY: {{(Leak|Address)}}Sanitizer: 2780 byte(s) leaked in 3 
allocation(s).



___
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] [compiler-rt] 9a5261e - [lsan] Parse suppressions just before leak reporting

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-29T17:28:31-08:00
New Revision: 9a5261efd75530d10ce7a346e8127ba1f00db085

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

LOG: [lsan] Parse suppressions just before leak reporting

Without leaks suppressions are not needed.

Added: 


Modified: 
compiler-rt/lib/lsan/lsan_common.cpp

Removed: 




diff  --git a/compiler-rt/lib/lsan/lsan_common.cpp 
b/compiler-rt/lib/lsan/lsan_common.cpp
index ddedfa0830e1..ac7536757743 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -65,8 +65,24 @@ void RegisterLsanFlags(FlagParser *parser, Flags *f) {
 if (flags()->log_threads) Report(__VA_ARGS__); \
   } while (0)
 
-ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
-static SuppressionContext *suppression_ctx = nullptr;
+class LeakSuppressionContext {
+  bool parsed = false;
+  SuppressionContext context;
+
+  Suppression *GetSuppressionForAddr(uptr addr);
+  void LazyParse();
+
+ public:
+  LeakSuppressionContext(const char *supprression_types[],
+ int suppression_types_num)
+  : context(supprression_types, suppression_types_num) {}
+
+  Suppression *GetSuppressionForStack(u32 stack_trace_id);
+  void PrintMatchedSuppressions();
+};
+
+ALIGNED(64) static char 
suppression_placeholder[sizeof(LeakSuppressionContext)];
+static LeakSuppressionContext *suppression_ctx = nullptr;
 static const char kSuppressionLeak[] = "leak";
 static const char *kSuppressionTypes[] = { kSuppressionLeak };
 static const char kStdSuppressions[] =
@@ -86,14 +102,20 @@ static const char kStdSuppressions[] =
 void InitializeSuppressions() {
   CHECK_EQ(nullptr, suppression_ctx);
   suppression_ctx = new (suppression_placeholder)
-  SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
-  suppression_ctx->ParseFromFile(flags()->suppressions);
-  if (&__lsan_default_suppressions)
-suppression_ctx->Parse(__lsan_default_suppressions());
-  suppression_ctx->Parse(kStdSuppressions);
+  LeakSuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
 }
 
-static SuppressionContext *GetSuppressionContext() {
+void LeakSuppressionContext::LazyParse() {
+  if (!parsed) {
+parsed = true;
+context.ParseFromFile(flags()->suppressions);
+if (&__lsan_default_suppressions)
+  context.Parse(__lsan_default_suppressions());
+context.Parse(kStdSuppressions);
+  }
+}
+
+static LeakSuppressionContext *GetSuppressionContext() {
   CHECK(suppression_ctx);
   return suppression_ctx;
 }
@@ -532,18 +554,20 @@ static void CollectLeaksCb(uptr chunk, void *arg) {
   }
 }
 
-static void PrintMatchedSuppressions() {
+void LeakSuppressionContext::PrintMatchedSuppressions() {
   InternalMmapVector matched;
-  GetSuppressionContext()->GetMatched(&matched);
+  context.GetMatched(&matched);
   if (!matched.size())
 return;
   const char *line = "-";
   Printf("%s\n", line);
   Printf("Suppressions used:\n");
   Printf("  count  bytes template\n");
-  for (uptr i = 0; i < matched.size(); i++)
-Printf("%7zu %10zu %s\n", static_cast(atomic_load_relaxed(
-&matched[i]->hit_count)), matched[i]->weight, matched[i]->templ);
+  for (uptr i = 0; i < matched.size(); i++) {
+Printf("%7zu %10zu %s\n",
+   static_cast(atomic_load_relaxed(&matched[i]->hit_count)),
+   matched[i]->weight, matched[i]->templ);
+  }
   Printf("%s\n\n", line);
 }
 
@@ -623,7 +647,7 @@ static bool CheckForLeaks() {
 param.leak_report.ReportTopLeaks(flags()->max_leaks);
   }
   if (common_flags()->print_suppressions)
-PrintMatchedSuppressions();
+GetSuppressionContext()->PrintMatchedSuppressions();
   if (unsuppressed_count > 0) {
 param.leak_report.PrintSummary();
 return true;
@@ -651,21 +675,20 @@ static int DoRecoverableLeakCheck() {
 
 void DoRecoverableLeakCheckVoid() { DoRecoverableLeakCheck(); }
 
-static Suppression *GetSuppressionForAddr(uptr addr) {
+Suppression *LeakSuppressionContext::GetSuppressionForAddr(uptr addr) {
   Suppression *s = nullptr;
 
   // Suppress by module name.
-  SuppressionContext *suppressions = GetSuppressionContext();
   if (const char *module_name =
   Symbolizer::GetOrInit()->GetModuleNameForPc(addr))
-if (suppressions->Match(module_name, kSuppressionLeak, &s))
+if (context.Match(module_name, kSuppressionLeak, &s))
   return s;
 
   // Suppress by file or function name.
   SymbolizedStack *frames = Symbolizer::GetOrInit()->SymbolizePC(addr);
   for (SymbolizedStack *cur = frames; cur; cur = cur->next) {
-if (suppressions->Match(cur->info.function, kSuppressionLeak, &s) ||
-suppressions->Match(cur->info.file, kSuppress

[llvm-branch-commits] [compiler-rt] 9b25b80 - [NFC][lsan] Extract PrintResults function

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-29T17:28:31-08:00
New Revision: 9b25b8068df3b2f34938eea17749c72939131d84

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

LOG: [NFC][lsan] Extract PrintResults function

Added: 


Modified: 
compiler-rt/lib/lsan/lsan_common.cpp

Removed: 




diff  --git a/compiler-rt/lib/lsan/lsan_common.cpp 
b/compiler-rt/lib/lsan/lsan_common.cpp
index ac7536757743..77e7d85e8c9f 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -618,6 +618,28 @@ static void CheckForLeaksCallback(const 
SuspendedThreadsList &suspended_threads,
   param->success = true;
 }
 
+static bool PrintResults(LeakReport &report) {
+  uptr unsuppressed_count = report.UnsuppressedLeakCount();
+  if (unsuppressed_count) {
+Decorator d;
+Printf(
+"\n"
+"="
+"\n");
+Printf("%s", d.Error());
+Report("ERROR: LeakSanitizer: detected memory leaks\n");
+Printf("%s", d.Default());
+report.ReportTopLeaks(flags()->max_leaks);
+  }
+  if (common_flags()->print_suppressions)
+GetSuppressionContext()->PrintMatchedSuppressions();
+  if (unsuppressed_count > 0) {
+report.PrintSummary();
+return true;
+  }
+  return false;
+}
+
 static bool CheckForLeaks() {
   if (&__lsan_is_turned_off && __lsan_is_turned_off())
 return false;
@@ -635,24 +657,7 @@ static bool CheckForLeaks() {
 Die();
   }
   param.leak_report.ApplySuppressions();
-  uptr unsuppressed_count = param.leak_report.UnsuppressedLeakCount();
-  if (unsuppressed_count > 0) {
-Decorator d;
-Printf("\n"
-   "="
-   "\n");
-Printf("%s", d.Error());
-Report("ERROR: LeakSanitizer: detected memory leaks\n");
-Printf("%s", d.Default());
-param.leak_report.ReportTopLeaks(flags()->max_leaks);
-  }
-  if (common_flags()->print_suppressions)
-GetSuppressionContext()->PrintMatchedSuppressions();
-  if (unsuppressed_count > 0) {
-param.leak_report.PrintSummary();
-return true;
-  }
-  return false;
+  return PrintResults(param.leak_report);
 }
 
 static bool has_reported_leaks = false;



___
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] 452eddf - [NFC][CodeGen] Add sanitize-dtor-zero-size-field test

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-05T16:39:48-08:00
New Revision: 452eddf30bfcd0f8ade9796ef24b3e8773ef1618

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

LOG: [NFC][CodeGen] Add sanitize-dtor-zero-size-field test

The test demonstrates invalid behaviour which will be fixed soon.

Added: 
clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp

Modified: 


Removed: 




diff  --git a/clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp 
b/clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp
new file mode 100644
index ..e876f93e49eb
--- /dev/null
+++ b/clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp
@@ -0,0 +1,378 @@
+// RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor 
-disable-llvm-passes -std=c++20 -triple=x86_64-pc-linux -emit-llvm -o - %s | 
FileCheck %s --implicit-check-not "call void @__sanitizer_dtor_callback"
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor 
-disable-llvm-passes -std=c++20 -triple=x86_64-pc-linux -emit-llvm -o - %s | 
FileCheck %s --implicit-check-not "call void @__sanitizer_dtor_callback"
+
+// This test convers invalid behaviour which will be fixed in followup patches.
+
+struct Empty {};
+
+struct EmptyNonTrivial {
+  ~EmptyNonTrivial();
+};
+
+struct Trivial {
+  int a;
+  char c;
+};
+static_assert(sizeof(Trivial) == 8);
+
+struct NonTrivial {
+  int a;
+  char c;
+  ~NonTrivial();
+};
+static_assert(sizeof(NonTrivial) == 8);
+
+namespace T0 {
+struct Struct {
+  Trivial f1;
+  int f2;
+  char f3;
+  ~Struct(){};
+} var;
+static_assert(sizeof(Struct) == 16);
+} // namespace T0
+// CHECK-LABEL: define {{.*}} @_ZN2T06StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
+// CHECK-NEXT:ret void
+
+namespace empty {
+namespace T1 {
+struct Struct {
+  NonTrivial nt;
+  Trivial f1;
+  int f2;
+  char f3;
+} var;
+static_assert(sizeof(Struct) == 24);
+} // namespace T1
+// CHECK-LABEL: define {{.*}} @_ZN5empty2T16StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
+// CHECK-NEXT:ret void
+
+namespace T2 {
+struct Struct {
+  Trivial f1;
+  NonTrivial nt;
+  int f2;
+  char f3;
+} var;
+static_assert(sizeof(Struct) == 24);
+} // namespace T2
+// CHECK-LABEL: define {{.*}} @_ZN5empty2T26StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
+// CHECK-NEXT:ret void
+
+namespace T3 {
+struct Struct {
+  Trivial f1;
+  int f2;
+  NonTrivial nt;
+  char f3;
+} var;
+static_assert(sizeof(Struct) == 24);
+} // namespace T3
+// CHECK-LABEL: define {{.*}} @_ZN5empty2T36StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
+// CHECK-NEXT:ret void
+
+namespace T4 {
+struct Struct {
+  Trivial f1;
+  int f2;
+  char f3;
+  NonTrivial nt;
+} var;
+static_assert(sizeof(Struct) == 24);
+} // namespace T4
+// CHECK-LABEL: define {{.*}} @_ZN5empty2T46StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 16)
+// CHECK-NEXT:ret void
+
+namespace T5 {
+struct Struct {
+  [[no_unique_address]] Empty e;
+  NonTrivial nt;
+  Trivial f1;
+  int f2;
+  char f3;
+} var;
+static_assert(sizeof(Struct) == 24);
+} // namespace T5
+// CHECK-LABEL: define {{.*}} @_ZN5empty2T56StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
+// CHECK-NEXT:ret void
+
+namespace T6 {
+struct Struct {
+  NonTrivial nt;
+  [[no_unique_address]] Empty e;
+  Trivial f1;
+  int f2;
+  char f3;
+} var;
+static_assert(sizeof(Struct) == 24);
+} // namespace T6
+// CHECK-LABEL: define {{.*}} @_ZN5empty2T66StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 21)
+// CHECK-NEXT:ret void
+
+namespace T7 {
+struct Struct {
+  Trivial f1;
+  NonTrivial nt;
+  [[no_unique_address]] Empty e;
+  int f2;
+  char f3;
+} var;
+static_assert(sizeof(Struct) == 24);
+} // namespace T7
+// CHECK-LABEL: define {{.*}} @_ZN5empty2T76StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 21)
+// CHECK-NEXT:ret void
+
+namespace T8 {
+struct Struct {
+  Trivial f1;
+  [[no_unique_address]] Empty e;
+  NonTrivial nt;
+  int f2;
+  char f3;
+} var;
+static_assert(sizeof(Struct) == 24);
+} // namespace T8
+// CHECK-LABEL: define {{.*}} @_ZN5empty2T86StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
+// CHECK-NEXT:ret void
+
+namespace 

[llvm-branch-commits] [compiler-rt] 9a02370 - [lsan] Ignore inderect leaks referenced by suppressed blocks

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-30T19:11:39-08:00
New Revision: 9a0237011b7e9e8111757365d1cb322fbbb086ae

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

LOG: [lsan] Ignore inderect leaks referenced by suppressed blocks

This makes suppression list to work similar to __lsan_ignore_object.

Existing behavior was inconsistent and very inconvenient for complex
data structures.

Example:

struct B;
struct A { B* ptr; };
A* t = makeA();
t->ptr = makeB();

Before the patch: if makeA suppressed by suppression file, lsan will
still report the makeB() leak, so we need two suppressions.

After the patch: a single makeA suppression is enough (the same as a
single __lsan_ignore_object(t)).

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

Added: 


Modified: 
compiler-rt/lib/lsan/lsan_common.cpp
compiler-rt/lib/lsan/lsan_common.h
compiler-rt/test/lsan/TestCases/suppressions_file.cpp

Removed: 




diff  --git a/compiler-rt/lib/lsan/lsan_common.cpp 
b/compiler-rt/lib/lsan/lsan_common.cpp
index 77e7d85e8c9f..ab7500ce32cf 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -68,9 +68,11 @@ void RegisterLsanFlags(FlagParser *parser, Flags *f) {
 class LeakSuppressionContext {
   bool parsed = false;
   SuppressionContext context;
+  bool suppressed_stacks_sorted = true;
+  InternalMmapVector suppressed_stacks;
 
   Suppression *GetSuppressionForAddr(uptr addr);
-  void LazyParse();
+  void LazyInit();
 
  public:
   LeakSuppressionContext(const char *supprression_types[],
@@ -78,6 +80,14 @@ class LeakSuppressionContext {
   : context(supprression_types, suppression_types_num) {}
 
   Suppression *GetSuppressionForStack(u32 stack_trace_id);
+
+  const InternalMmapVector &GetSortedSuppressedStacks() {
+if (!suppressed_stacks_sorted) {
+  suppressed_stacks_sorted = true;
+  SortAndDedup(suppressed_stacks);
+}
+return suppressed_stacks;
+  }
   void PrintMatchedSuppressions();
 };
 
@@ -105,7 +115,7 @@ void InitializeSuppressions() {
   LeakSuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
 }
 
-void LeakSuppressionContext::LazyParse() {
+void LeakSuppressionContext::LazyInit() {
   if (!parsed) {
 parsed = true;
 context.ParseFromFile(flags()->suppressions);
@@ -412,6 +422,24 @@ static void MarkIndirectlyLeakedCb(uptr chunk, void *arg) {
   }
 }
 
+static void IgnoredSuppressedCb(uptr chunk, void *arg) {
+  CHECK(arg);
+  chunk = GetUserBegin(chunk);
+  LsanMetadata m(chunk);
+  if (!m.allocated() || m.tag() == kIgnored)
+return;
+
+  const InternalMmapVector &suppressed =
+  *static_cast *>(arg);
+  uptr idx = InternalLowerBound(suppressed, m.stack_trace_id());
+  if (idx >= suppressed.size() || m.stack_trace_id() != suppressed[idx])
+return;
+
+  LOG_POINTERS("Suppressed: chunk %p-%p of size %zu.\n", chunk,
+   chunk + m.requested_size(), m.requested_size());
+  m.set_tag(kIgnored);
+}
+
 // ForEachChunk callback. If chunk is marked as ignored, adds its address to
 // frontier.
 static void CollectIgnoredCb(uptr chunk, void *arg) {
@@ -495,6 +523,12 @@ void ProcessPC(Frontier *frontier) {
 // Sets the appropriate tag on each chunk.
 static void ClassifyAllChunks(SuspendedThreadsList const &suspended_threads,
   Frontier *frontier) {
+  const InternalMmapVector &suppressed_stacks =
+  GetSuppressionContext()->GetSortedSuppressedStacks();
+  if (!suppressed_stacks.empty()) {
+ForEachChunk(IgnoredSuppressedCb,
+ const_cast *>(&suppressed_stacks));
+  }
   ForEachChunk(CollectIgnoredCb, frontier);
   ProcessGlobalRegions(frontier);
   ProcessThreads(suspended_threads, frontier);
@@ -643,21 +677,41 @@ static bool PrintResults(LeakReport &report) {
 static bool CheckForLeaks() {
   if (&__lsan_is_turned_off && __lsan_is_turned_off())
 return false;
-  EnsureMainThreadIDIsCorrect();
-  CheckForLeaksParam param;
-  LockStuffAndStopTheWorld(CheckForLeaksCallback, ¶m);
+  // Inside LockStuffAndStopTheWorld we can't run symbolizer, so we can't match
+  // suppressions. However if a stack id was previously suppressed, it should 
be
+  // suppressed in future checks as well.
+  for (int i = 0;; ++i) {
+EnsureMainThreadIDIsCorrect();
+CheckForLeaksParam param;
+LockStuffAndStopTheWorld(CheckForLeaksCallback, ¶m);
+if (!param.success) {
+  Report("LeakSanitizer has encountered a fatal error.\n");
+  Report(
+  "HINT: For debugging, try setting environment variable "
+  "LSAN_OPTIONS=verbosity=1:log_threads=1\n");
+  Report(
+  "HINT: LeakSanitizer does not work under ptrace (strace, gdb, "
+  "etc)\n");
+  Die();
+}
+// No new suppressions stack

[llvm-branch-commits] [llvm] 19e7741 - [TargetMachine] Set dso_local for memprof

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-05T21:11:04-08:00
New Revision: 19e7741fef775b2f4f497c44b6aeab350f43f9a7

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

LOG: [TargetMachine] Set dso_local for memprof

Similar to 5582a7987662a92eda5d883b88fc4586e755acf5

Added: 


Modified: 
llvm/lib/Target/TargetMachine.cpp

Removed: 




diff  --git a/llvm/lib/Target/TargetMachine.cpp 
b/llvm/lib/Target/TargetMachine.cpp
index f214a47ba702..d9c894537b72 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -163,10 +163,11 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
 // If the symbol is defined, it cannot be preempted.
 if (!GV->isDeclarationForLinker())
   return true;
-// FIXME asan does not call setDSOLocal appropriately. Fix asan and delete
-// the hack.
+// FIXME Sanitizers do not call setDSOLocal appropriately. Fix sanitizers
+// and delete the hack.
 if (RM == Reloc::Static && !GV->isThreadLocal() &&
-M.getFunction("asan.module_ctor"))
+(M.getFunction("asan.module_ctor") ||
+ M.getFunction("memprof.module_ctor")))
   return true;
   } else if (TT.isOSBinFormatELF()) {
 // If dso_local allows AsmPrinter::getSymbolPreferLocal to use a local



___
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] 3e1cb0d - [CodeGen][MSan] Don't use offsets of zero-sized fields

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-07T13:37:40-08:00
New Revision: 3e1cb0db8a79b19996fcea210b639fe513a5eaf3

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

LOG: [CodeGen][MSan] Don't use offsets of zero-sized fields

Such fields will likely have offset zero making
__sanitizer_dtor_callback poisoning wrong regions.
E.g. it can poison base class member from derived class constructor.

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

Added: 


Modified: 
clang/lib/CodeGen/CGClass.cpp
clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 0d17037db864..b900ed70152e 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1700,12 +1700,23 @@ namespace {
 return FieldHasTrivialDestructorBody(Context, F);
   };
 
+  auto IsZeroSize = [&](const FieldDecl *F) {
+return F->isZeroSize(Context);
+  };
+
+  // Poison blocks of fields with trivial destructors making sure that 
block
+  // begin and end do not point to zero-sized fields. They don't have
+  // correct offsets so can't be used to calculate poisoning range.
   for (auto It = Fields.begin(); It != Fields.end();) {
-It = std::find_if(It, Fields.end(), IsTrivial);
+It = std::find_if(It, Fields.end(), [&](const FieldDecl *F) {
+  return IsTrivial(F) && !IsZeroSize(F);
+});
 if (It == Fields.end())
   break;
 auto Start = It++;
-It = std::find_if_not(It, Fields.end(), IsTrivial);
+It = std::find_if(It, Fields.end(), [&](const FieldDecl *F) {
+  return !IsTrivial(F) && !IsZeroSize(F);
+});
 
 PoisonMembers(CGF, (*Start)->getFieldIndex(),
   It == Fields.end() ? -1 : (*It)->getFieldIndex());

diff  --git a/clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp 
b/clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp
index e876f93e49eb..74ba612f9922 100644
--- a/clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp
+++ b/clang/test/CodeGenCXX/sanitize-dtor-zero-size-field.cpp
@@ -1,8 +1,6 @@
 // RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor 
-disable-llvm-passes -std=c++20 -triple=x86_64-pc-linux -emit-llvm -o - %s | 
FileCheck %s --implicit-check-not "call void @__sanitizer_dtor_callback"
 // RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor 
-disable-llvm-passes -std=c++20 -triple=x86_64-pc-linux -emit-llvm -o - %s | 
FileCheck %s --implicit-check-not "call void @__sanitizer_dtor_callback"
 
-// This test convers invalid behaviour which will be fixed in followup patches.
-
 struct Empty {};
 
 struct EmptyNonTrivial {
@@ -115,7 +113,7 @@ struct Struct {
 static_assert(sizeof(Struct) == 24);
 } // namespace T6
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T66StructD2Ev(
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 21)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
 // CHECK-NEXT:ret void
 
 namespace T7 {
@@ -130,7 +128,7 @@ static_assert(sizeof(Struct) == 24);
 } // namespace T7
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T76StructD2Ev(
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 21)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
 // CHECK-NEXT:ret void
 
 namespace T8 {
@@ -160,7 +158,7 @@ static_assert(sizeof(Struct) == 24);
 } // namespace T9
 // CHECK-LABEL: define {{.*}} @_ZN5empty2T96StructD2Ev(
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 21)
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
 // CHECK-NEXT:ret void
 
 namespace T10 {
@@ -190,7 +188,6 @@ static_assert(sizeof(Struct) == 24);
 } // namespace T11
 // CHECK-LABEL: define {{.*}} @_ZN5empty3T116StructD2Ev(
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 16)
-// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 24)
 // CHECK-NEXT:ret void
 
 namespace T12 {
@@ -317,6 +314,7 @@ struct Struct {
 static_assert(sizeof(Struct) == 24);
 } // namespace T8
 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T86StructD2Ev(
+// CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
 // CHECK: call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
 // CHECK-NEXT:ret void
 
@@ -346,6 +344,7 @@ struct Struct {
 static_assert(sizeof(Struct) == 24);
 } // namespace T10
 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial3T106StructD2Ev(
+// CHECK:   

[llvm-branch-commits] [compiler-rt] ababeca - [NFC][sanitizer] Add SortAndDedup function

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-29T14:01:43-08:00
New Revision: ababeca34b3f3a355010803d5b59513906a0d590

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

LOG: [NFC][sanitizer] Add SortAndDedup function

Added: 


Modified: 
compiler-rt/lib/sanitizer_common/sanitizer_common.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp

Removed: 




diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index 60d1c62b0681..a6532eee164d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -682,6 +682,27 @@ enum ModuleArch {
   kModuleArchRISCV64
 };
 
+// Sorts and removes duplicates from the container.
+template >
+void SortAndDedup(Container &v, Compare comp = {}) {
+  Sort(v.data(), v.size(), comp);
+  uptr size = v.size();
+  if (size < 2)
+return;
+  uptr last = 0;
+  for (uptr i = 1; i < size; ++i) {
+if (comp(v[last], v[i])) {
+  ++last;
+  if (last != i)
+v[last] = v[i];
+} else {
+  CHECK(!comp(v[i], v[last]));
+}
+  }
+  v.resize(last + 1);
+}
+
 // Opens the file 'file_name" and reads up to 'max_len' bytes.
 // The resulting buffer is mmaped and stored in '*buff'.
 // Returns true if file was successfully opened and read.

diff  --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp 
b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp
index 1d0806c4c404..4d9f2c1c831b 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp
@@ -269,6 +269,35 @@ TEST(SanitizerCommon, InternalLowerBoundVsStdLowerBound) {
   }
 }
 
+class SortAndDedupTest : public ::testing::TestWithParam> {};
+
+TEST_P(SortAndDedupTest, SortAndDedup) {
+  std::vector v_std = GetParam();
+  std::sort(v_std.begin(), v_std.end());
+  v_std.erase(std::unique(v_std.begin(), v_std.end()), v_std.end());
+
+  std::vector v = GetParam();
+  SortAndDedup(v);
+
+  EXPECT_EQ(v_std, v);
+}
+
+const std::vector kSortAndDedupTests[] = {
+{},
+{1},
+{1, 1},
+{1, 1, 1},
+{1, 2, 3},
+{3, 2, 1},
+{1, 2, 2, 3},
+{3, 3, 2, 1, 2},
+{3, 3, 2, 1, 2},
+{1, 2, 1, 1, 2, 1, 1, 1, 2, 2},
+{1, 3, 3, 2, 3, 1, 3, 1, 4, 4, 2, 1, 4, 1, 1, 2, 2},
+};
+INSTANTIATE_TEST_CASE_P(SortAndDedupTest, SortAndDedupTest,
+::testing::ValuesIn(kSortAndDedupTests));
+
 #if SANITIZER_LINUX && !SANITIZER_ANDROID
 TEST(SanitizerCommon, FindPathToBinary) {
   char *true_path = FindPathToBinary("true");



___
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] 6e614b0 - [NFC][MSan] Round up OffsetPtr in PoisonMembers

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2020-12-07T19:57:49-08:00
New Revision: 6e614b0c7ed3a9a66428f342bf2a4b3700525395

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

LOG: [NFC][MSan] Round up OffsetPtr in PoisonMembers

getFieldOffset(layoutStartOffset)  is expected to point to the first trivial
field or the one which follows non-trivial. So it must be byte aligned already.
However this is not obvious without assumptions about callers.
This patch will avoid the need in such assumptions.

Depends on D92727.

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

Added: 


Modified: 
clang/lib/CodeGen/CGClass.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index b900ed70152e..1c32929414a5 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -18,6 +18,7 @@
 #include "TargetInfo.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/CharUnits.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/EvaluatedExprVisitor.h"
 #include "clang/AST/RecordLayout.h"
@@ -1729,37 +1730,35 @@ namespace {
 /// \param layoutEndOffset index of the ASTRecordLayout field to
 /// end poisoning (exclusive)
 void PoisonMembers(CodeGenFunction &CGF, unsigned layoutStartOffset,
- unsigned layoutEndOffset) {
+   unsigned layoutEndOffset) {
   ASTContext &Context = CGF.getContext();
   const ASTRecordLayout &Layout =
   Context.getASTRecordLayout(Dtor->getParent());
 
-  llvm::ConstantInt *OffsetSizePtr = llvm::ConstantInt::get(
-  CGF.SizeTy,
-  Context.toCharUnitsFromBits(Layout.getFieldOffset(layoutStartOffset))
-  .getQuantity());
+  // It's a first trivia field so it should be at the begining of char,
+  // still round up start offset just in case.
+  CharUnits PoisonStart =
+  Context.toCharUnitsFromBits(Layout.getFieldOffset(layoutStartOffset) 
+
+  Context.getCharWidth() - 1);
+  llvm::ConstantInt *OffsetSizePtr =
+  llvm::ConstantInt::get(CGF.SizeTy, PoisonStart.getQuantity());
 
   llvm::Value *OffsetPtr = CGF.Builder.CreateGEP(
   CGF.Builder.CreateBitCast(CGF.LoadCXXThis(), CGF.Int8PtrTy),
   OffsetSizePtr);
 
-  CharUnits::QuantityType PoisonSize;
+  CharUnits PoisonEnd;
   if (layoutEndOffset >= Layout.getFieldCount()) {
-PoisonSize = Layout.getNonVirtualSize().getQuantity() -
- Context.toCharUnitsFromBits(
-Layout.getFieldOffset(layoutStartOffset))
- .getQuantity();
+PoisonEnd = Layout.getNonVirtualSize();
   } else {
-PoisonSize = Context.toCharUnitsFromBits(
-Layout.getFieldOffset(layoutEndOffset) -
-Layout.getFieldOffset(layoutStartOffset))
- .getQuantity();
+PoisonEnd =
+
Context.toCharUnitsFromBits(Layout.getFieldOffset(layoutEndOffset));
   }
-
-  if (PoisonSize == 0)
+  CharUnits PoisonSize = PoisonEnd - PoisonStart;
+  if (!PoisonSize.isPositive())
 return;
 
-  EmitSanitizerDtorCallback(CGF, OffsetPtr, PoisonSize);
+  EmitSanitizerDtorCallback(CGF, OffsetPtr, PoisonSize.getQuantity());
 }
   };
 



___
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] 698ae90 - [RegisterScavenging] Fix assert in scavengeRegisterBackwards

2021-01-03 Thread Simon Cook via llvm-branch-commits

Author: Craig Blackmore
Date: 2020-12-18T16:57:05Z
New Revision: 698ae90f306248aafbfb5c85cdd9bb81c387bb59

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

LOG: [RegisterScavenging] Fix assert in scavengeRegisterBackwards

According to the documentation, if a spill is required to make a
register available and AllowSpill is false, then NoRegister should be
returned, however, this scenario was actually triggering an assertion
failure.

This patch moves the assertion after the handling of AllowSpill.

Authored by: Lewis Revill

Reviewed By: arsenm

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

Added: 


Modified: 
llvm/lib/CodeGen/RegisterScavenging.cpp

Removed: 




diff  --git a/llvm/lib/CodeGen/RegisterScavenging.cpp 
b/llvm/lib/CodeGen/RegisterScavenging.cpp
index ab9a1d66b835..ab8f4fd9778b 100644
--- a/llvm/lib/CodeGen/RegisterScavenging.cpp
+++ b/llvm/lib/CodeGen/RegisterScavenging.cpp
@@ -573,9 +573,8 @@ Register RegScavenger::scavengeRegisterBackwards(const 
TargetRegisterClass &RC,
 RestoreAfter);
   MCPhysReg Reg = P.first;
   MachineBasicBlock::iterator SpillBefore = P.second;
-  assert(Reg != 0 && "No register left to scavenge!");
   // Found an available register?
-  if (SpillBefore == MBB.end()) {
+  if (Reg != 0 && SpillBefore == MBB.end()) {
 LLVM_DEBUG(dbgs() << "Scavenged free register: " << printReg(Reg, TRI)
<< '\n');
 return Reg;
@@ -584,6 +583,8 @@ Register RegScavenger::scavengeRegisterBackwards(const 
TargetRegisterClass &RC,
   if (!AllowSpill)
 return 0;
 
+  assert(Reg != 0 && "No register left to scavenge!");
+
   MachineBasicBlock::iterator ReloadAfter =
 RestoreAfter ? std::next(MBBI) : MBBI;
   MachineBasicBlock::iterator ReloadBefore = std::next(ReloadAfter);



___
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] [compiler-rt] 8d33f08 - [compiler-rt sanitizer] Use our own PTRACE_GETREGSET if it does not exist.

2021-01-03 Thread Vitaly Buka via llvm-branch-commits

Author: Jeroen Dobbelaere
Date: 2020-12-09T01:08:14-08:00
New Revision: 8d33f08844a171472a59ef3f1ea6edb1e9fb9843

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

LOG: [compiler-rt sanitizer] Use our own PTRACE_GETREGSET if it does not exist.

On RH66 does not support 'PTRACE_GETREGSET'. This change makes this part of 
compiler-rt build again on older os-es

Reviewed By: vitalybuka

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

Added: 


Modified: 
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp

Removed: 




diff  --git 
a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
index 2ecf87b096a1..53cfddcfbe0b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
@@ -490,6 +490,9 @@ typedef user_regs_struct regs_struct;
 #ifndef NT_X86_XSTATE
 #define NT_X86_XSTATE 0x202
 #endif
+#ifndef PTRACE_GETREGSET
+#define PTRACE_GETREGSET 0x4204
+#endif
 // Compiler may use FP registers to store pointers.
 static constexpr uptr kExtraRegs[] = {NT_X86_XSTATE, NT_FPREGSET};
 



___
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-tools-extra] 59810c5 - [clang-tidy] Fix windows tests

2021-01-03 Thread Nathan James via llvm-branch-commits

Author: Nathan James
Date: 2021-01-04T00:39:34Z
New Revision: 59810c51e761f241f23f45a120d5c3518983d2d8

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

LOG: [clang-tidy] Fix windows tests

Attempt to fix the 2 failing tests identifier in 48646.
Appears that python3 doesn't like nested double quotes in single quoted 
strings, hopefully nested single quotes in double quoted strings is a-ok.

Reviewed By: thakis

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

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-macro-usage-custom.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-macro-usage-custom.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-macro-usage-custom.cpp
index b3075324efdb..5e70aa00d40e 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-macro-usage-custom.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-macro-usage-custom.cpp
@@ -1,9 +1,6 @@
-// FIXME: PR48646
-// UNSUPPORTED: system-windows
-
 // RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \
-// RUN: -config='{CheckOptions: \
-// RUN:  [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: 
"DEBUG_*|TEST_*"}]}' --
+// RUN: -config="{CheckOptions: \
+// RUN:  [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: 
'DEBUG_*|TEST_*'}]}" --
 
 #ifndef INCLUDE_GUARD
 #define INCLUDE_GUARD

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp
index 625b7dc9134a..22a8c7159a99 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp
@@ -1,15 +1,12 @@
-// FIXME: PR48646
-// UNSUPPORTED: system-windows
-
 // RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
-// RUN:   -config='{CheckOptions: [ \
+// RUN:   -config="{CheckOptions: [ \
 // RUN: {key: readability-identifier-naming.ParameterCase, value: 
CamelCase}, \
-// RUN: {key: readability-identifier-naming.ParameterIgnoredRegexp, value: 
"^[a-z]{1,2}$"}, \
+// RUN: {key: readability-identifier-naming.ParameterIgnoredRegexp, value: 
'^[a-z]{1,2}$'}, \
 // RUN: {key: readability-identifier-naming.ClassCase, value: CamelCase}, \
-// RUN: {key: readability-identifier-naming.ClassIgnoredRegexp, value: 
"^fo$|^fooo$"}, \
+// RUN: {key: readability-identifier-naming.ClassIgnoredRegexp, value: 
'^fo$|^fooo$'}, \
 // RUN: {key: readability-identifier-naming.StructCase, value: CamelCase}, 
\
-// RUN: {key: readability-identifier-naming.StructIgnoredRegexp, value: 
"sooo|so|soo|$invalidregex["} \
-// RUN:  ]}'
+// RUN: {key: readability-identifier-naming.StructIgnoredRegexp, value: 
'sooo|so|soo|$invalidregex['} \
+// RUN:  ]}"
 
 int testFunc(int a, char **b);
 int testFunc(int ab, char **ba);



___
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] [compiler-rt] 6988f7a - [compiler-rt] [Sanitizers] Extend ThreadDescriptorSize() for glibc-2.32-2.fc33.x86_64+i686

2021-01-03 Thread Jan Kratochvil via llvm-branch-commits

Author: Jan Kratochvil
Date: 2021-01-04T03:21:04+01:00
New Revision: 6988f7a6f4a78a2235a8132e10582ebf7aba9752

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

LOG: [compiler-rt] [Sanitizers] Extend ThreadDescriptorSize() for 
glibc-2.32-2.fc33.x86_64+i686

before:
  $ echo 'int main(){}'|clang -g -fsanitize=leak -x c++ -;./a.out
  Tracer caught signal 11: addr=0x7f4f73da5f40 pc=0x4222c8 sp=0x7f4f72cffd40
  ==1164171==LeakSanitizer has encountered a fatal error.
  ==1164171==HINT: For debugging, try setting environment variable 
LSAN_OPTIONS=verbosity=1:log_threads=1
  ==1164171==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)
  $ _

after:
  $ echo 'int main(){}'|clang -g -fsanitize=leak -x c++ -;./a.out)
  $ _

I haven't verified the size cannot be affected by Fedora patches of
upstream glibc-2.32 - but I do not expect upstream glibc-2.32 would have
the last sizes `(1216, 2304)` from 2013 around glibc-2.12.

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

Added: 


Modified: 
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Removed: 




diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index 47c84ce1b060..2421387e5f01 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -294,8 +294,10 @@ uptr ThreadDescriptorSize() {
   val = FIRST_32_SECOND_64(1168, 2288);
 else if (minor <= 14)
   val = FIRST_32_SECOND_64(1168, 2304);
-else
+else if (minor < 32)  // Unknown version
   val = FIRST_32_SECOND_64(1216, 2304);
+else  // minor == 32
+  val = FIRST_32_SECOND_64(1344, 2496);
   }
 #elif defined(__mips__)
   // TODO(sagarthakur): add more values as per 
diff erent glibc versions.



___
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] [flang] 6280bc1 - [Flang][openmp][5.0] Add task_reduction clause.

2021-01-03 Thread Sameeran joshi via llvm-branch-commits

Author: sameeran joshi
Date: 2021-01-04T08:48:11+05:30
New Revision: 6280bc1cc34ad67c4297b2da1ff3920f410e6894

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

LOG: [Flang][openmp][5.0] Add task_reduction clause.

See OMP-5.0 2.19.5.5 task_reduction Clause.
To add a positive test case we need `taskgroup` directive which is not added 
hence skipping the test.
This is a dependency for `taskgroup` construct.

Reviewed By: clementval

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

Co-authored-by: Valentin Clement 

Added: 


Modified: 
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/test/Semantics/omp-clause-validity01.f90
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/flang/include/flang/Parser/parse-tree.h 
b/flang/include/flang/Parser/parse-tree.h
index 7e258b668576..119a92bee211 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3415,7 +3415,7 @@ struct OmpReductionOperator {
 // variable-name-list)
 struct OmpReductionClause {
   TUPLE_CLASS_BOILERPLATE(OmpReductionClause);
-  std::tuple> t;
+  std::tuple t;
 };
 
 // OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list)

diff  --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 1386b2b16a78..3a0d28cd9c12 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -102,7 +102,7 @@ 
TYPE_PARSER(construct(Parser{}) ||
 construct(Parser{}))
 
 TYPE_PARSER(construct(
-Parser{} / ":", nonemptyList(designator)))
+Parser{} / ":", Parser{}))
 
 // OMP 5.0 2.11.4  ALLOCATE ([allocator:] variable-name-list)
 TYPE_PARSER(construct(
@@ -220,6 +220,9 @@ TYPE_PARSER(
parenthesized(Parser{}))) ||
 "REDUCTION" >>
 construct(parenthesized(Parser{})) ||
+"TASK_REDUCTION" >>
+construct(construct(
+parenthesized(Parser{}))) ||
 "RELAXED" >> construct(construct()) ||
 "RELEASE" >> construct(construct()) ||
 "SAFELEN" >> construct(construct(

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index fdb694f3d26f..ba54a0a84fa7 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2016,7 +2016,7 @@ class UnparseVisitor {
 Word("REDUCTION(");
 Walk(std::get(x.t));
 Put(":");
-Walk(std::get>(x.t), ",");
+Walk(std::get(x.t));
 Put(")");
   }
   void Unparse(const OmpAllocateClause &x) {

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index e2c8333ce7ee..a144c7a2b57b 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -419,6 +419,7 @@ CHECK_SIMPLE_CLAUSE(Mergeable, OMPC_mergeable)
 CHECK_SIMPLE_CLAUSE(Nogroup, OMPC_nogroup)
 CHECK_SIMPLE_CLAUSE(Notinbranch, OMPC_notinbranch)
 CHECK_SIMPLE_CLAUSE(Nowait, OMPC_nowait)
+CHECK_SIMPLE_CLAUSE(TaskReduction, OMPC_task_reduction)
 CHECK_SIMPLE_CLAUSE(To, OMPC_to)
 CHECK_SIMPLE_CLAUSE(Uniform, OMPC_uniform)
 CHECK_SIMPLE_CLAUSE(Untied, OMPC_untied)

diff  --git a/flang/lib/Semantics/check-omp-structure.h 
b/flang/lib/Semantics/check-omp-structure.h
index a966eaf8c4a7..ccd0e08a8c08 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -155,6 +155,7 @@ class OmpStructureChecker
   void Enter(const parser::OmpClause::Safelen &);
   void Enter(const parser::OmpClause::Shared &);
   void Enter(const parser::OmpClause::Simdlen &);
+  void Enter(const parser::OmpClause::TaskReduction &);
   void Enter(const parser::OmpClause::ThreadLimit &);
   void Enter(const parser::OmpClause::To &);
   void Enter(const parser::OmpClause::Link &);

diff  --git a/flang/test/Semantics/omp-clause-validity01.f90 
b/flang/test/Semantics/omp-clause-validity01.f90
index 3f5345137866..1d689ea91699 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -349,7 +349,8 @@
 !  collapse-clause
 
   a = 0.0
-  !$omp simd private(b) reduction(+:a)
+  !ERROR: TASK_REDUCTION clause is not allowed on the SIMD directive
+  !$omp simd private(b) reduction(+:a) task_reduction(+:a)
   do i = 1, N
  a = a + b + 3.14
   enddo
@@ -449,7 +450,8 @@
   enddo
 
   !ERROR: At most one NUM_TASKS clause can appear on the TASKLOOP directive
-  !$omp taskloop num_tasks(3) num_tasks(2)
+  !ERROR: TASK_REDUCTION clause is not allowed on the TASKLOOP directive
+  !$omp taskloop num_tas

[llvm-branch-commits] [llvm] 05e6ac4 - [IROutliner] Removing a duplicate addition, causing overestimates in IROutliner.

2021-01-03 Thread Andrew Litteken via llvm-branch-commits

Author: Andrew Litteken
Date: 2021-01-03T23:36:28-06:00
New Revision: 05e6ac4eb811f332ece873381561b0fad0974256

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

LOG: [IROutliner] Removing a duplicate addition, causing overestimates in 
IROutliner.

There was an extra addition left over from a previous commit for the
cost model, this removes it.

Added: 


Modified: 
llvm/lib/Transforms/IPO/IROutliner.cpp
llvm/test/Transforms/IROutliner/opt-remarks.ll
llvm/test/Transforms/IROutliner/outlining-calls.ll

llvm/test/Transforms/IROutliner/outlining-compatible-and-attribute-transfer.ll

llvm/test/Transforms/IROutliner/outlining-compatible-or-attribute-transfer.ll
llvm/test/Transforms/IROutliner/outlining-different-constants.ll
llvm/test/Transforms/IROutliner/outlining-different-structure.ll
llvm/test/Transforms/IROutliner/outlining-isomorphic-predicates.ll

Removed: 




diff  --git a/llvm/lib/Transforms/IPO/IROutliner.cpp 
b/llvm/lib/Transforms/IPO/IROutliner.cpp
index e506d84b2c29..3acde6b6ece0 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -1286,7 +1286,6 @@ unsigned 
IROutliner::findBenefitFromAllRegions(OutlinableGroup &CurrentGroup) {
 RegionBenefit += Region->getBenefit(TTI);
 LLVM_DEBUG(dbgs() << "Adding: " << RegionBenefit
   << " saved instructions to overfall benefit.\n");
-CurrentGroup.Benefit += RegionBenefit;
   }
 
   return RegionBenefit;
@@ -1405,7 +1404,8 @@ void IROutliner::findCostBenefit(Module &M, 
OutlinableGroup &CurrentGroup) {
   LLVM_DEBUG(dbgs() << "Adding: " << OverallArgumentNum
 << " instructions to cost for each argument in the new"
 << " function.\n");
-  CurrentGroup.Cost += 2 * OverallArgumentNum * TargetTransformInfo::TCC_Basic;
+  CurrentGroup.Cost +=
+  NumRegions * OverallArgumentNum * TargetTransformInfo::TCC_Basic;
   LLVM_DEBUG(dbgs() << "Current Cost: " << CurrentGroup.Cost << "\n");
 
   // Each argument needs to either be loaded into a register or onto the stack.
@@ -1416,7 +1416,7 @@ void IROutliner::findCostBenefit(Module &M, 
OutlinableGroup &CurrentGroup) {
 << " function " << NumRegions << " times for the "
 << "needed argument handling at the call site.\n");
   CurrentGroup.Cost +=
-  2 * OverallArgumentNum * TargetTransformInfo::TCC_Basic * NumRegions;
+  OverallArgumentNum * TargetTransformInfo::TCC_Basic * NumRegions;
   LLVM_DEBUG(dbgs() << "Current Cost: " << CurrentGroup.Cost << "\n");
 
   CurrentGroup.Cost += findCostForOutputBlocks(M, CurrentGroup, TTI);

diff  --git a/llvm/test/Transforms/IROutliner/opt-remarks.ll 
b/llvm/test/Transforms/IROutliner/opt-remarks.ll
index 0658aba18f6e..2a26e5b08784 100644
--- a/llvm/test/Transforms/IROutliner/opt-remarks.ll
+++ b/llvm/test/Transforms/IROutliner/opt-remarks.ll
@@ -5,13 +5,16 @@
 ; RUN:  -pass-remarks-output=%t < %s
 ; RUN: cat %t | FileCheck -check-prefix=YAML %s
 
-; CHECK: remark: :0:0: outlined 2 regions with decrease of 31 
instructions at locations   
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 5 instructions at locations  
+; CHECK: remark: :0:0: outlined 2 regions with decrease of 2 
instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 6 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 7 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 8 instructions at locations  
 ; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 9 instructions at locations  
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 13 instructions at locations  
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 17 instructions at locations  
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 21 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 10 instructions at locations  
 ; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 7 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 8 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 13 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 10 instructions at locations  
 
 ; YAML: --- !Passed
 ; YAML-NEXT: Pass:iroutli

[llvm-branch-commits] [llvm] 5c95162 - [IROutliner] Refactoring errors in the cost model from past patches.

2021-01-03 Thread Andrew Litteken via llvm-branch-commits

Author: Andrew Litteken
Date: 2021-01-04T00:11:18-06:00
New Revision: 5c951623bc8965fa1e89660f2f5f4a2944e4981a

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

LOG: [IROutliner] Refactoring errors in the cost model from past patches.

There were was the reuse of a variable that should not have been
occurred due to confusion during committing patches.

Added: 


Modified: 
llvm/lib/Transforms/IPO/IROutliner.cpp
llvm/test/Transforms/IROutliner/opt-remarks.ll
llvm/test/Transforms/IROutliner/outlining-cost-model.ll

Removed: 




diff  --git a/llvm/lib/Transforms/IPO/IROutliner.cpp 
b/llvm/lib/Transforms/IPO/IROutliner.cpp
index 3acde6b6ece0..0e5e1dd0886e 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -1405,7 +1405,7 @@ void IROutliner::findCostBenefit(Module &M, 
OutlinableGroup &CurrentGroup) {
 << " instructions to cost for each argument in the new"
 << " function.\n");
   CurrentGroup.Cost +=
-  NumRegions * OverallArgumentNum * TargetTransformInfo::TCC_Basic;
+  OverallArgumentNum * TargetTransformInfo::TCC_Basic;
   LLVM_DEBUG(dbgs() << "Current Cost: " << CurrentGroup.Cost << "\n");
 
   // Each argument needs to either be loaded into a register or onto the stack.
@@ -1416,7 +1416,7 @@ void IROutliner::findCostBenefit(Module &M, 
OutlinableGroup &CurrentGroup) {
 << " function " << NumRegions << " times for the "
 << "needed argument handling at the call site.\n");
   CurrentGroup.Cost +=
-  OverallArgumentNum * TargetTransformInfo::TCC_Basic * NumRegions;
+  2 * OverallArgumentNum * TargetTransformInfo::TCC_Basic * NumRegions;
   LLVM_DEBUG(dbgs() << "Current Cost: " << CurrentGroup.Cost << "\n");
 
   CurrentGroup.Cost += findCostForOutputBlocks(M, CurrentGroup, TTI);

diff  --git a/llvm/test/Transforms/IROutliner/opt-remarks.ll 
b/llvm/test/Transforms/IROutliner/opt-remarks.ll
index 2a26e5b08784..7172908a84a8 100644
--- a/llvm/test/Transforms/IROutliner/opt-remarks.ll
+++ b/llvm/test/Transforms/IROutliner/opt-remarks.ll
@@ -5,18 +5,48 @@
 ; RUN:  -pass-remarks-output=%t < %s
 ; RUN: cat %t | FileCheck -check-prefix=YAML %s
 
-; CHECK: remark: :0:0: outlined 2 regions with decrease of 2 
instructions at locations  
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 6 instructions at locations  
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 7 instructions at locations  
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 8 instructions at locations  
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 9 instructions at locations  
+; CHECK: remark: :0:0: did not outline 2 regions due to estimated 
increase of 12 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 5 instructions at locations  
+; CHECK-NEXT: remark: :0:0: outlined 2 regions with decrease of 2 
instructions at locations  
 ; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 10 instructions at locations  
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 7 instructions at locations  
-; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 8 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 11 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 12 instructions at locations  
 ; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 13 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 14 instructions at locations  
 ; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 10 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 11 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 17 instructions at locations  
+; CHECK-NEXT: remark: :0:0: did not outline 2 regions due to 
estimated increase of 13 instructions at locations  
 
-; YAML: --- !Passed
+; YAML: --- !Missed
+; YAML-NEXT: Pass:iroutliner
+; YAML-NEXT: Name:WouldNotDecreaseSize
+; YAML-NEXT: Function:function3
+; YAML-NEXT: Args:
+; YAML-NEXT:   - String:  'did not outline '
+; YAML-NEXT:   - String:  '2'
+; YAML-NEXT:   - String:  ' regions due to estimated increase of '
+; YAML-NEXT:   - Instruct

[llvm-branch-commits] [llvm] f6515b0 - [PowerPC] Do not fold `cmp(d|w)` and `subf` instruction to `subf.` if `nsw` is not present

2021-01-03 Thread Kai Luo via llvm-branch-commits

Author: Kai Luo
Date: 2021-01-04T07:54:15Z
New Revision: f6515b05205d4324d174dd1f7455c6c8e6671e6b

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

LOG: [PowerPC] Do not fold `cmp(d|w)` and `subf` instruction to `subf.` if 
`nsw` is not present

In `PPCInstrInfo::optimizeCompareInstr` we seek opportunities to fold 
`cmp(d|w)` and `subf` as an `subf.`. However, if `subf.` gets overflow, `cr0` 
can't reflect the correct order, violating the semantics of `cmp(d|w)`.

Fixed https://bugs.llvm.org/show_bug.cgi?id=47830.

Reviewed By: #powerpc, nemanjai

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

Added: 


Modified: 
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
llvm/test/CodeGen/PowerPC/pr47830.ll

Removed: 




diff  --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp 
b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
index deac690a7611..75a498b807cd 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -2141,6 +2141,14 @@ bool PPCInstrInfo::optimizeCompareInstr(MachineInstr 
&CmpInstr, Register SrcReg,
   if (NewOpC == -1)
 return false;
 
+  // This transformation should not be performed if `nsw` is missing and is not
+  // `equalityOnly` comparison. Since if there is overflow, sub_lt, sub_gt in
+  // CRReg do not reflect correct order. If `equalityOnly` is true, sub_eq in
+  // CRReg can reflect if compared values are equal, this optz is still valid.
+  if (!equalityOnly && (NewOpC == PPC::SUBF_rec || NewOpC == PPC::SUBF8_rec) &&
+  Sub && !Sub->getFlag(MachineInstr::NoSWrap))
+return false;
+
   // If we have SUB(r1, r2) and CMP(r2, r1), the condition code based on CMP
   // needs to be updated to be based on SUB.  Push the condition code
   // operands to OperandsToUpdate.  If it is safe to remove CmpInstr, the

diff  --git a/llvm/test/CodeGen/PowerPC/pr47830.ll 
b/llvm/test/CodeGen/PowerPC/pr47830.ll
index be61a81462c2..bd320907a341 100644
--- a/llvm/test/CodeGen/PowerPC/pr47830.ll
+++ b/llvm/test/CodeGen/PowerPC/pr47830.ll
@@ -5,8 +5,9 @@
 define i64 @f(i64 %a, i64 %b) {
 ; CHECK-LABEL: f:
 ; CHECK:   # %bb.0:
-; CHECK-NEXT:sub. r3, r3, r4
-; CHECK-NEXT:isellt r3, 0, r3
+; CHECK-NEXT:sub r5, r3, r4
+; CHECK-NEXT:cmpd r3, r4
+; CHECK-NEXT:isellt r3, 0, r5
 ; CHECK-NEXT:blr
   %c = icmp slt i64 %a, %b
   %d = sub i64 %a, %b



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