1 # This patch is needed for ISPC for Xe only
3 # 1. Transformation of add to or is not safe for VC backend.
4 # 2. bswap intrinsics is not supported in VC backend yet.
5 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
6 index d01a021bf3f4..bccce825a03d 100644
7 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
8 +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
10 #include "llvm/ADT/APInt.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/SmallVector.h"
13 +#include "llvm/ADT/Triple.h"
14 #include "llvm/Analysis/InstructionSimplify.h"
15 #include "llvm/Analysis/ValueTracking.h"
16 #include "llvm/IR/Constant.h"
17 @@ -1369,9 +1370,12 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
21 - // A+B --> A|B iff A and B have no bits set in common.
22 - if (haveNoCommonBitsSet(LHS, RHS, DL, &AC, &I, &DT))
23 - return BinaryOperator::CreateOr(LHS, RHS);
24 + // Disable this transformation for ISPC SPIR-V
25 + if (!Triple(I.getModule()->getTargetTriple()).isSPIR()) {
26 + // A+B --> A|B iff A and B have no bits set in common.
27 + if (haveNoCommonBitsSet(LHS, RHS, DL, &AC, &I, &DT))
28 + return BinaryOperator::CreateOr(LHS, RHS);
31 // add (select X 0 (sub n A)) A --> select X A n
33 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
34 index 120852c44474..8de55311ce3e 100644
35 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
36 +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
37 @@ -2671,9 +2671,12 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
38 if (Instruction *FoldedLogic = foldBinOpIntoSelectOrPhi(I))
41 - if (Instruction *BitOp = matchBSwapOrBitReverse(I, /*MatchBSwaps*/ true,
42 - /*MatchBitReversals*/ true))
44 + // Disable this transformation for ISPC SPIR-V
45 + if (!Triple(I.getModule()->getTargetTriple()).isSPIR()) {
46 + if (Instruction *BitOp = matchBSwapOrBitReverse(I, /*MatchBSwaps*/ true,
47 + /*MatchBitReversals*/ true))
51 if (Instruction *Funnel = matchFunnelShift(I, *this))