diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 060e66175..cbfae3b60 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -29,6 +29,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/MemoryLocation.h" +#include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/VectorUtils.h" @@ -6951,6 +6952,13 @@ SDValue DAGCombiner::visitAND(SDNode *N) { if (areBitwiseNotOfEachother(N0, N1)) return DAG.getConstant(APInt::getZero(VT.getScalarSizeInBits()), DL, VT); + if (isOneConstant(N0) || isOneConstant(N1)) { + auto &F = DAG.getMachineFunction().getFunction(); + OptimizationRemarkAnalysis R("clang-vs-clang", "and1", N->getDebugLoc(), &F.getEntryBlock()); + R << "clang-vs-clang: clang sees 1&...; please take this away before clang does something bad"; + DAG.getORE().emit(R); + } + // fold vector ops if (VT.isVector()) { if (SDValue FoldedVOp = SimplifyVBinOp(N, DL)) @@ -10339,6 +10347,13 @@ SDValue DAGCombiner::visitSRA(SDNode *N) { ConstantSDNode *N1C = isConstOrConstSplat(N1); + if (N1C && N1C->getAPIntValue() == OpSizeInBits - 1) { + auto &F = DAG.getMachineFunction().getFunction(); + OptimizationRemarkAnalysis R("clang-vs-clang", "sra1", N->getDebugLoc(), &F.getEntryBlock()); + R << "clang-vs-clang: clang sees signed>>(bits-1); please take this away before clang does something bad"; + DAG.getORE().emit(R); + } + // fold (sra (sra x, c1), c2) -> (sra x, (add c1, c2)) // clamp (add c1, c2) to max shift. if (N0.getOpcode() == ISD::SRA) { @@ -10538,6 +10553,13 @@ SDValue DAGCombiner::visitSRL(SDNode *N) { DAG.MaskedValueIsZero(SDValue(N, 0), APInt::getAllOnes(OpSizeInBits))) return DAG.getConstant(0, DL, VT); + if (N1C && N1C->getAPIntValue() == OpSizeInBits - 1) { + auto &F = DAG.getMachineFunction().getFunction(); + OptimizationRemarkAnalysis R("clang-vs-clang", "srl1", N->getDebugLoc(), &F.getEntryBlock()); + R << "clang-vs-clang: clang sees unsigned>>(bits-1); please take this away before clang does something bad"; + DAG.getORE().emit(R); + } + // fold (srl (srl x, c1), c2) -> 0 or (srl x, (add c1, c2)) if (N0.getOpcode() == ISD::SRL) { auto MatchOutOfRange = [OpSizeInBits](ConstantSDNode *LHS,