Skip to content

Commit

Permalink
Merged master:654e8aadfdda into amd-gfx:aab61286598f
Browse files Browse the repository at this point in the history
Local branch amd-gfx aab6128 Merged master:c814eca3e4c6 into amd-gfx:3d52bae5ee3a
Remote branch master 654e8aa [MLIR] Consider AffineIfOp when getting the index set of an Op wrapped in nested loops
  • Loading branch information
Sw authored and Sw committed Aug 8, 2020
2 parents aab6128 + 654e8aa commit 41523d1
Show file tree
Hide file tree
Showing 15 changed files with 433 additions and 80 deletions.
2 changes: 1 addition & 1 deletion libcxx/test/libcxx/fuzzing/fuzzer_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "../../../fuzzing/fuzzing.cpp"

const char* TestCaseSetOne[] = {"", "s", "bac",
"bacasf"
"bacasf",
"lkajseravea",
"adsfkajdsfjkas;lnc441324513,34535r34525234",
"b*c",
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3991,6 +3991,12 @@ bool X86DAGToDAGISel::tryVPTERNLOG(SDNode *N) {

switch (N->getOpcode()) {
default: llvm_unreachable("Unexpected opcode!");
case X86ISD::ANDNP:
if (A == N0)
Imm &= ~TernlogMagicA;
else
Imm = ~(Imm) & TernlogMagicA;
break;
case ISD::AND: Imm &= TernlogMagicA; break;
case ISD::OR: Imm |= TernlogMagicA; break;
case ISD::XOR: Imm ^= TernlogMagicA; break;
Expand Down Expand Up @@ -4592,6 +4598,11 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
return;
break;

case X86ISD::ANDNP:
if (tryVPTERNLOG(Node))
return;
break;

case ISD::AND:
if (NVT.isVector() && NVT.getVectorElementType() == MVT::i1) {
// Try to form a masked VPTESTM. Operands can be in either order.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39608,7 +39608,7 @@ combineVSelectWithAllOnesOrZeros(SDNode *N, SelectionDAG &DAG,
if (TValIsAllOnes && FValIsAllZeros)
return DAG.getBitcast(VT, Cond);

if (!DCI.isBeforeLegalize() && !TLI.isTypeLegal(CondVT))
if (!TLI.isTypeLegal(CondVT))
return SDValue();

// vselect Cond, 111..., X -> or Cond, X
Expand Down
22 changes: 22 additions & 0 deletions llvm/test/CodeGen/X86/avx512vl-logic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1297,3 +1297,25 @@ define <4 x i64> @ternlog_masky_xor_and_mask_ymm(<4 x i64> %x, <4 x i64> %y, <4
%c = select <4 x i1> %m, <4 x i64> %b, <4 x i64> %y
ret <4 x i64> %c
}

define <4 x i32> @ternlog_andn_or(<4 x i32> %x, <4 x i32> %y, <4 x i32> %z) {
; CHECK-LABEL: ternlog_andn_or:
; CHECK: ## %bb.0:
; CHECK-NEXT: vpternlogd $14, %xmm2, %xmm1, %xmm0
; CHECK-NEXT: retq
%a = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
%b = or <4 x i32> %y, %z
%c = and <4 x i32> %a, %b
ret <4 x i32> %c
}

define <4 x i32> @ternlog_andn_or_2(<4 x i32> %x, <4 x i32> %y, <4 x i32> %z) {
; CHECK-LABEL: ternlog_andn_or_2:
; CHECK: ## %bb.0:
; CHECK-NEXT: vpternlogd $16, %xmm2, %xmm1, %xmm0
; CHECK-NEXT: retq
%a = or <4 x i32> %y, %z
%b = xor <4 x i32> %a, <i32 -1, i32 -1, i32 -1, i32 -1>
%c = and <4 x i32> %x, %b
ret <4 x i32> %c
}
14 changes: 14 additions & 0 deletions llvm/test/Reduce/remove-function-bodies-used-in-globals.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s

; CHECK-INTERESTINGNESS: @alias =
; CHECK-FINAL: @alias = alias void (i32), void (i32)* undef

@alias = alias void (i32), void (i32)* @func

; CHECK-FINAL-NOT: @func()

define void @func(i32 %arg) {
entry:
ret void
}
44 changes: 19 additions & 25 deletions llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,36 @@

#include "ReduceFunctions.h"
#include "Delta.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Instructions.h"
#include <set>
#include <iterator>
#include <vector>

using namespace llvm;

/// Removes all the Defined Functions (as well as their calls)
/// Removes all the Defined Functions
/// that aren't inside any of the desired Chunks.
static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
Module *Program) {
Oracle O(ChunksToKeep);

// Get functions inside desired chunks
std::set<Function *> FuncsToKeep;
for (auto &F : *Program)
if (O.shouldKeep())
FuncsToKeep.insert(&F);

// Delete out-of-chunk functions, and replace their users with undef
std::vector<Function *> FuncsToRemove;
SetVector<Instruction *> InstrsToRemove;
for (auto &F : *Program)
if (!FuncsToKeep.count(&F)) {
for (auto U : F.users()) {
U->replaceAllUsesWith(UndefValue::get(U->getType()));
if (auto *I = dyn_cast<Instruction>(U))
InstrsToRemove.insert(I);
}
FuncsToRemove.push_back(&F);
}
// Record all out-of-chunk functions.
std::vector<std::reference_wrapper<Function>> FuncsToRemove;
copy_if(Program->functions(), std::back_inserter(FuncsToRemove),
[&O](auto &unused) { return !O.shouldKeep(); });

for (auto *I : InstrsToRemove)
I->eraseFromParent();
// Then, drop body of each of them. We want to batch this and do nothing else
// here so that minimal number of remaining exteranal uses will remain.
for (Function &F : FuncsToRemove)
F.dropAllReferences();

for (auto *F : FuncsToRemove)
F->eraseFromParent();
// And finally, we can actually delete them.
for (Function &F : FuncsToRemove) {
// Replace all *still* remaining uses with undef.
F.replaceAllUsesWith(UndefValue::get(F.getType()));
// And finally, fully drop it.
F.eraseFromParent();
}
}

/// Counts the amount of non-declaration functions and prints their
Expand Down
12 changes: 7 additions & 5 deletions mlir/include/mlir/Analysis/AffineAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ void getReachableAffineApplyOps(ArrayRef<Value> operands,
SmallVectorImpl<Operation *> &affineApplyOps);

/// Builds a system of constraints with dimensional identifiers corresponding to
/// the loop IVs of the forOps appearing in that order. Bounds of the loop are
/// used to add appropriate inequalities. Any symbols founds in the bound
/// operands are added as symbols in the system. Returns failure for the yet
/// unimplemented cases.
/// the loop IVs of the forOps and AffineIfOp's operands appearing in
/// that order. Bounds of the loop are used to add appropriate inequalities.
/// Constraints from the index sets of AffineIfOp are also added. Any symbols
/// founds in the bound operands are added as symbols in the system. Returns
/// failure for the yet unimplemented cases. `ops` accepts both AffineForOp and
/// AffineIfOp.
// TODO: handle non-unit strides.
LogicalResult getIndexSet(MutableArrayRef<AffineForOp> forOps,
LogicalResult getIndexSet(MutableArrayRef<Operation *> ops,
FlatAffineConstraints *domain);

/// Encapsulates a memref load or store access information.
Expand Down
10 changes: 10 additions & 0 deletions mlir/include/mlir/Analysis/AffineStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace mlir {

class AffineCondition;
class AffineForOp;
class AffineIfOp;
class AffineMap;
class AffineValueMap;
class IntegerSet;
Expand Down Expand Up @@ -215,6 +216,15 @@ class FlatAffineConstraints {
// TODO: add support for non-unit strides.
LogicalResult addAffineForOpDomain(AffineForOp forOp);

/// Adds constraints imposed by the `affine.if` operation. These constraints
/// are collected from the IntegerSet attached to the given `affine.if`
/// instance argument (`ifOp`). It is asserted that:
/// 1) The IntegerSet of the given `affine.if` instance should not contain
/// semi-affine expressions,
/// 2) The columns of the constraint system created from `ifOp` should match
/// the columns in the current one regarding numbers and values.
void addAffineIfOpDomain(AffineIfOp ifOp);

/// Adds a lower or an upper bound for the identifier at the specified
/// position with constraints being drawn from the specified bound map and
/// operands. If `eq` is true, add a single equality equal to the bound map's
Expand Down
6 changes: 6 additions & 0 deletions mlir/include/mlir/Analysis/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class Value;
// TODO: handle 'affine.if' ops.
void getLoopIVs(Operation &op, SmallVectorImpl<AffineForOp> *loops);

/// Populates 'ops' with IVs of the loops surrounding `op`, along with
/// `affine.if` operations interleaved between these loops, ordered from the
/// outermost `affine.for` or `affine.if` operation to the innermost one.
void getEnclosingAffineForAndIfOps(Operation &op,
SmallVectorImpl<Operation *> *ops);

/// Returns the nesting depth of this operation, i.e., the number of loops
/// surrounding this operation.
unsigned getNestingDepth(Operation *op);
Expand Down
Loading

0 comments on commit 41523d1

Please sign in to comment.