diff --git a/llvm/lib/Transforms/InstCombine/CMakeLists.txt b/llvm/lib/Transforms/InstCombine/CMakeLists.txt --- a/llvm/lib/Transforms/InstCombine/CMakeLists.txt +++ b/llvm/lib/Transforms/InstCombine/CMakeLists.txt @@ -12,6 +12,7 @@ InstCombineCompares.cpp InstCombineLoadStoreAlloca.cpp InstCombineMulDivRem.cpp + InstCombineNegator.cpp InstCombinePHI.cpp InstCombineSelect.cpp InstCombineShifts.cpp diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1682,12 +1682,10 @@ if (Instruction *X = foldVectorBinop(I)) return X; - // (A*B)-(A*C) -> A*(B-C) etc - if (Value *V = SimplifyUsingDistributiveLaws(I)) - return replaceInstUsesWith(I, V); + Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); // If this is a 'B = x-(-A)', change to B = x+A. - Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); + // We deal with this without involving Negator to preserve NSW flag. if (Value *V = dyn_castNegVal(Op1)) { BinaryOperator *Res = BinaryOperator::CreateAdd(Op0, V); @@ -1704,6 +1702,34 @@ return Res; } + auto Cleanup = [this, &I, &Op0, &Op1]() -> Instruction * { + if (Instruction *Ext = narrowMathIfNoOverflow(I)) + return Ext; + + bool Changed = false; + if (!I.hasNoSignedWrap() && willNotOverflowSignedSub(Op0, Op1, I)) { + Changed = true; + I.setHasNoSignedWrap(true); + } + if (!I.hasNoUnsignedWrap() && willNotOverflowUnsignedSub(Op0, Op1, I)) { + Changed = true; + I.setHasNoUnsignedWrap(true); + } + + return Changed ? &I : nullptr; + }; + + // First, let's try to interpret `sub a, b` as `add a, (sub 0, b)`, + // and let's try to sink `(sub 0, b)` into `b` itself. + if (Value *NegOp1 = Negator::Negate(match(Op0, m_ZeroInt()), Op1, *this)) + return BinaryOperator::CreateAdd(NegOp1, Op0); + if (match(Op0, m_ZeroInt())) + return Cleanup(); // Should have been handled in Negator! + + // (A*B)-(A*C) -> A*(B-C) etc + if (Value *V = SimplifyUsingDistributiveLaws(I)) + return replaceInstUsesWith(I, V); + if (I.getType()->isIntOrIntVectorTy(1)) return BinaryOperator::CreateXor(Op0, Op1); @@ -1720,22 +1746,7 @@ if (match(Op0, m_OneUse(m_Add(m_Value(X), m_AllOnes())))) return BinaryOperator::CreateAdd(Builder.CreateNot(Op1), X); - // Y - (X + 1) --> ~X + Y - if (match(Op1, m_OneUse(m_Add(m_Value(X), m_One())))) - return BinaryOperator::CreateAdd(Builder.CreateNot(X), Op0); - - // Y - ~X --> (X + 1) + Y - if (match(Op1, m_OneUse(m_Not(m_Value(X))))) { - return BinaryOperator::CreateAdd( - Builder.CreateAdd(Op0, ConstantInt::get(I.getType(), 1)), X); - } - if (Constant *C = dyn_cast(Op0)) { - // -f(x) -> f(-x) if possible. - if (match(C, m_Zero())) - if (Value *Neg = freelyNegateValue(Op1)) - return replaceInstUsesWith(I, Neg); - Value *X; if (match(Op1, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) // C - (zext bool) --> bool ? C - 1 : C @@ -1770,26 +1781,12 @@ } const APInt *Op0C; - if (match(Op0, m_APInt(Op0C))) { - if (Op0C->isNullValue() && Op1->hasOneUse()) { - Value *LHS, *RHS; - SelectPatternFlavor SPF = matchSelectPattern(Op1, LHS, RHS).Flavor; - if (SPF == SPF_ABS || SPF == SPF_NABS) { - // This is a negate of an ABS/NABS pattern. Just swap the operands - // of the select. - cast(Op1)->swapValues(); - // Don't swap prof metadata, we didn't change the branch behavior. - return replaceInstUsesWith(I, Op1); - } - } - + if (match(Op0, m_APInt(Op0C)) && Op0C->isMask()) { // Turn this into a xor if LHS is 2^n-1 and the remaining bits are known // zero. - if (Op0C->isMask()) { - KnownBits RHSKnown = computeKnownBits(Op1, 0, &I); - if ((*Op0C | RHSKnown.Zero).isAllOnesValue()) - return BinaryOperator::CreateXor(Op1, Op0); - } + KnownBits RHSKnown = computeKnownBits(Op1, 0, &I); + if ((*Op0C | RHSKnown.Zero).isAllOnesValue()) + return BinaryOperator::CreateXor(Op1, Op0); } { @@ -1919,49 +1916,6 @@ return BinaryOperator::CreateAnd( Op0, Builder.CreateNot(Y, Y->getName() + ".not")); - if (Op1->hasOneUse()) { - Value *Y = nullptr, *Z = nullptr; - Constant *C = nullptr; - - // (X - (Y - Z)) --> (X + (Z - Y)). - if (match(Op1, m_Sub(m_Value(Y), m_Value(Z)))) - return BinaryOperator::CreateAdd(Op0, - Builder.CreateSub(Z, Y, Op1->getName())); - - // Subtracting -1/0 is the same as adding 1/0: - // sub [nsw] Op0, sext(bool Y) -> add [nsw] Op0, zext(bool Y) - // 'nuw' is dropped in favor of the canonical form. - if (match(Op1, m_SExt(m_Value(Y))) && - Y->getType()->getScalarSizeInBits() == 1) { - Value *Zext = Builder.CreateZExt(Y, I.getType()); - BinaryOperator *Add = BinaryOperator::CreateAdd(Op0, Zext); - Add->setHasNoSignedWrap(I.hasNoSignedWrap()); - return Add; - } - // sub [nsw] X, zext(bool Y) -> add [nsw] X, sext(bool Y) - // 'nuw' is dropped in favor of the canonical form. - if (match(Op1, m_ZExt(m_Value(Y))) && Y->getType()->isIntOrIntVectorTy(1)) { - Value *Sext = Builder.CreateSExt(Y, I.getType()); - BinaryOperator *Add = BinaryOperator::CreateAdd(Op0, Sext); - Add->setHasNoSignedWrap(I.hasNoSignedWrap()); - return Add; - } - - // X - A*-B -> X + A*B - // X - -A*B -> X + A*B - Value *A, *B; - if (match(Op1, m_c_Mul(m_Value(A), m_Neg(m_Value(B))))) - return BinaryOperator::CreateAdd(Op0, Builder.CreateMul(A, B)); - - // X - A*C -> X + A*-C - // No need to handle commuted multiply because multiply handling will - // ensure constant will be move to the right hand side. - if (match(Op1, m_Mul(m_Value(A), m_Constant(C))) && !isa(C)) { - Value *NewMul = Builder.CreateMul(A, ConstantExpr::getNeg(C)); - return BinaryOperator::CreateAdd(Op0, NewMul); - } - } - { // ~A - Min/Max(~A, O) -> Max/Min(A, ~O) - A // ~A - Min/Max(O, ~A) -> Max/Min(A, ~O) - A @@ -2036,20 +1990,7 @@ canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(I)) return V; - if (Instruction *Ext = narrowMathIfNoOverflow(I)) - return Ext; - - bool Changed = false; - if (!I.hasNoSignedWrap() && willNotOverflowSignedSub(Op0, Op1, I)) { - Changed = true; - I.setHasNoSignedWrap(true); - } - if (!I.hasNoUnsignedWrap() && willNotOverflowUnsignedSub(Op0, Op1, I)) { - Changed = true; - I.setHasNoUnsignedWrap(true); - } - - return Changed ? &I : nullptr; + return Cleanup(); } /// This eliminates floating-point negation in either 'fneg(X)' or diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -16,6 +16,7 @@ #define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/TargetFolder.h" @@ -471,7 +472,6 @@ bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const; bool shouldChangeType(Type *From, Type *To) const; Value *dyn_castNegVal(Value *V) const; - Value *freelyNegateValue(Value *V); Type *FindElementAtOffset(PointerType *PtrTy, int64_t Offset, SmallVectorImpl &NewIndices); @@ -513,7 +513,7 @@ Instruction *simplifyMaskedStore(IntrinsicInst &II); Instruction *simplifyMaskedGather(IntrinsicInst &II); Instruction *simplifyMaskedScatter(IntrinsicInst &II); - + /// Transform (zext icmp) to bitwise / integer operations in order to /// eliminate it. /// @@ -1014,6 +1014,55 @@ Value *Descale(Value *Val, APInt Scale, bool &NoSignedWrap); }; +namespace { + +// As a default, let's assume that we want to be aggressive, +// and attempt to traverse with no limits in attempt to sink negation. +static constexpr unsigned NegatorDefaultMaxDepth = ~0U; + +// Let's guesstimate that most often we will end up visiting/producing +// fairly small number of new instructions. +static constexpr unsigned NegatorMaxNodesSSO = 16; + +} // namespace + +class Negator final { + /// Top-to-bottom, def-to-use negated instruction tree we produced. + SmallVector NewInstructions; + + using BuilderTy = IRBuilder; + BuilderTy Builder; + + const bool IsTrulyNegation; + + Negator(LLVMContext &C, const DataLayout &DL, bool IsTrulyNegation); + +#if LLVM_ENABLE_STATS + unsigned NumValuesVisitedInThisNegator = 0; + ~Negator(); +#endif + + using Result = std::pair /*NewInstructions*/, + Value * /*NegatedRoot*/>; + + LLVM_NODISCARD Value *visit(Value *V, unsigned Depth); + + /// Recurse depth-first and attempt to sink the negation. + /// FIXME: use worklist? + LLVM_NODISCARD Optional run(Value *Root); + + Negator(const Negator &) = delete; + Negator(Negator &&) = delete; + Negator &operator=(const Negator &) = delete; + Negator &operator=(Negator &&) = delete; + +public: + /// Attempt to negate \p Root. Retuns nullptr if negation can't be performed, + /// otherwise returns negated value. + LLVM_NODISCARD static Value *Negate(bool LHSIsZero, Value *Root, + InstCombiner &IC); +}; + } // end namespace llvm #undef DEBUG_TYPE diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp new file mode 100644 --- /dev/null +++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp @@ -0,0 +1,370 @@ +//===- InstCombineNegator.cpp -----------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements sinking of negation into expression trees, +// as long as that can be done without increasing instruction count. +// +//===----------------------------------------------------------------------===// + +#include "InstCombineInternal.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Analysis/TargetFolder.h" +#include "llvm/Analysis/ValueTracking.h" +#include "llvm/IR/Constant.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/PatternMatch.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Use.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/DebugCounter.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include + +using namespace llvm; + +#define DEBUG_TYPE "instcombine" + +STATISTIC(NegatorTotalNegationsAttempted, + "Negator: Number of negations attempted to be sinked"); +STATISTIC(NegatorNumTreesNegated, + "Negator: Number of negations successfully sinked"); +STATISTIC(NegatorMaxDepthVisited, "Negator: Maximal traversal depth ever " + "reached while attempting to sink negation"); +STATISTIC(NegatorTimesDepthLimitReached, + "Negator: How many times did the traversal depth limit was reached " + "during sinking"); +STATISTIC( + NegatorNumValuesVisited, + "Negator: Total number of values visited during attempts to sink negation"); +STATISTIC(NegatorMaxTotalValuesVisited, + "Negator: Maximal number of values ever visited while attempting to " + "sink negation"); +STATISTIC(NegatorNumInstructionsCreatedTotal, + "Negator: Number of new negated instructions created, total"); +STATISTIC(NegatorMaxInstructionsCreated, + "Negator: Maximal number of new instructions created during negation " + "attempt"); +STATISTIC(NegatorNumInstructionsNegatedSuccess, + "Negator: Number of new negated instructions created in successful " + "negation sinking attempts"); + +DEBUG_COUNTER(NegatorCounter, "instcombine-negator", + "Controls Negator transformations in InstCombine pass"); + +static cl::opt + NegatorEnabled("instcombine-negator-enabled", cl::init(true), + cl::desc("Should we attempt to sink negations?")); + +static cl::opt + NegatorMaxDepth("instcombine-negator-max-depth", + cl::init(NegatorDefaultMaxDepth), + cl::desc("What is the maximal lookup depth when trying to " + "check for viability of negation sinking.")); + +Negator::Negator(LLVMContext &C, const DataLayout &DL, bool IsTrulyNegation_) + : Builder(C, TargetFolder(DL), + IRBuilderCallbackInserter([&](Instruction *I) { + ++NegatorNumInstructionsCreatedTotal; + NewInstructions.push_back(I); + })), + IsTrulyNegation(IsTrulyNegation_) {} + +#if LLVM_ENABLE_STATS +Negator::~Negator() { + NegatorMaxTotalValuesVisited.updateMax(NumValuesVisitedInThisNegator); +} +#endif + +// FIXME: can this be reworked into a worklist-based algorithm while preserving +// the depth-first, early bailout traversal? +LLVM_NODISCARD Value *Negator::visit(Value *V, unsigned Depth) { + NegatorMaxDepthVisited.updateMax(Depth); + ++NegatorNumValuesVisited; + +#if LLVM_ENABLE_STATS + ++NumValuesVisitedInThisNegator; +#endif + + // In i1, negation can simply be ignored. + if (V->getType()->isIntOrIntVectorTy(1)) + return V; + + Value *X; + + // -(-(X)) -> X. + if (match(V, m_Neg(m_Value(X)))) + return X; + + // Integral constants can be freely negated. + if (match(V, m_AnyIntegralConstant())) + return ConstantExpr::getNeg(cast(V), /*HasNUW=*/false, + /*HasNSW=*/false); + + // If we have a non-instruction, then give up. + if (!isa(V)) + return nullptr; + + // ZZZ + if (!V->hasOneUse() && !IsTrulyNegation) + return nullptr; + + auto *I = cast(V); + unsigned BitWidth = I->getType()->getScalarSizeInBits(); + + // We must preserve the insertion point and debug info that is set in the + // builder at the time this function is called. + InstCombiner::BuilderTy::InsertPointGuard Guard(Builder); + // And since we are trying to negate instruction I, that tells us about the + // insertion point and the debug info that we need to keep. + Builder.SetInsertPoint(I); + + // In some cases we can give the answer without further recursion. + switch (I->getOpcode()) { + case Instruction::Sub: + // `sub` is always negatible. + return Builder.CreateSub(I->getOperand(1), I->getOperand(0), + I->getName() + ".neg"); + case Instruction::Add: + // `inc` is always negatible. + if (match(I->getOperand(1), m_One())) + return Builder.CreateNot(I->getOperand(0), I->getName() + ".neg"); + break; + case Instruction::Xor: + // `not` is always negatible. + if (match(I, m_Not(m_Value(X)))) + return Builder.CreateAdd(X, ConstantInt::get(X->getType(), 1), + I->getName() + ".neg"); + break; + case Instruction::AShr: + case Instruction::LShr: { + // Right-shift sign bit smear is negatible. + const APInt *Op1Val; + if (match(I->getOperand(1), m_APInt(Op1Val)) && *Op1Val == BitWidth - 1) { + Value *BO = I->getOpcode() == Instruction::AShr + ? Builder.CreateLShr(I->getOperand(0), I->getOperand(1)) + : Builder.CreateAShr(I->getOperand(0), I->getOperand(1)); + if (auto *NewInstr = dyn_cast(BO)) { + NewInstr->copyIRFlags(I); + NewInstr->setName(I->getName() + ".neg"); + } + return BO; + } + break; + } + case Instruction::SDiv: + // `sdiv` is negatible if divisor is not undef/INT_MIN/1. + if (auto *Op1C = dyn_cast(I->getOperand(1))) { + if (!Op1C->containsUndefElement() && Op1C->isNotMinSignedValue() && + Op1C->isNotOneValue()) { + Value *BO = + Builder.CreateSDiv(I->getOperand(0), ConstantExpr::getNeg(Op1C), + I->getName() + ".neg"); + if (auto *NewInstr = dyn_cast(BO)) + NewInstr->setIsExact(I->isExact()); + return BO; + } + } + break; + case Instruction::SExt: + case Instruction::ZExt: + // `*ext` of i1 is always negatible + if (I->getOperand(0)->getType()->isIntOrIntVectorTy(1)) + return I->getOpcode() == Instruction::SExt + ? Builder.CreateZExt(I->getOperand(0), I->getType(), + I->getName() + ".neg") + : Builder.CreateSExt(I->getOperand(0), I->getType(), + I->getName() + ".neg"); + break; + default: + break; // Other instructions require recursive reasoning. + } + + // Rest of the logic is recursive, and if either the current instruction + // has other uses or if it's time to give up then it's time. + if (!V->hasOneUse()) + return nullptr; + if (Depth > NegatorMaxDepth) { + LLVM_DEBUG(dbgs() << "Negator: reached maximal allowed traversal depth in " + << *V << ". Giving up.\n"); + ++NegatorTimesDepthLimitReached; + return nullptr; + } + + switch (I->getOpcode()) { + case Instruction::PHI: { + // `phi` is negatible if all the incoming values are negatible. + PHINode *PHI = cast(I); + SmallVector NegatedIncomingValues(PHI->getNumOperands()); + for (auto I : zip(PHI->incoming_values(), NegatedIncomingValues)) { + if (!(std::get<1>(I) = visit(std::get<0>(I), Depth + 1))) // Early return. + return nullptr; + } + // All incoming values are indeed negatible. Create negated PHI node. + PHINode *NegatedPHI = Builder.CreatePHI( + PHI->getType(), PHI->getNumOperands(), PHI->getName() + ".neg"); + for (auto I : zip(NegatedIncomingValues, PHI->blocks())) + NegatedPHI->addIncoming(std::get<0>(I), std::get<1>(I)); + return NegatedPHI; + } + case Instruction::Select: { + { + // `abs`/`nabs` is always negatible. + Value *LHS, *RHS; + SelectPatternFlavor SPF = + matchSelectPattern(I, LHS, RHS, /*CastOp=*/nullptr, Depth).Flavor; + if (SPF == SPF_ABS || SPF == SPF_NABS) { + auto *NewSelect = cast(I->clone()); + // Just swap the operands of the select. + NewSelect->swapValues(); + // Don't swap prof metadata, we didn't change the branch behavior. + NewSelect->setName(I->getName() + ".neg"); + Builder.Insert(NewSelect); + return NewSelect; + } + } + // `select` is negatible if both hands of `select` are negatible. + Value *NegOp1 = visit(I->getOperand(1), Depth + 1); + if (!NegOp1) // Early return. + return nullptr; + Value *NegOp2 = visit(I->getOperand(2), Depth + 1); + if (!NegOp2) + return nullptr; + // Do preserve the metadata! + return Builder.CreateSelect(I->getOperand(0), NegOp1, NegOp2, + I->getName() + ".neg", /*MDFrom=*/I); + } + case Instruction::Trunc: { + // `trunc` is negatible if its operand is negatible. + Value *NegOp = visit(I->getOperand(0), Depth + 1); + if (!NegOp) // Early return. + return nullptr; + return Builder.CreateTrunc(NegOp, I->getType(), I->getName() + ".neg"); + } + case Instruction::Shl: { + // `shl` is negatible if the first operand is negatible. + Value *NegOp0 = visit(I->getOperand(0), Depth + 1); + if (!NegOp0) // Early return. + return nullptr; + return Builder.CreateShl(NegOp0, I->getOperand(1), I->getName() + ".neg"); + } + case Instruction::Add: { + // `add` is negatible if both of its operands are negatible. + Value *NegOp0 = visit(I->getOperand(0), Depth + 1); + if (!NegOp0) // Early return. + return nullptr; + Value *NegOp1 = visit(I->getOperand(1), Depth + 1); + if (!NegOp1) + return nullptr; + return Builder.CreateAdd(NegOp0, NegOp1, I->getName() + ".neg"); + } + case Instruction::Xor: + // `xor` is negatible if one of its operands is invertible. + // FIXME: InstCombineInverter? But how to connect Inverter and Negator? + if (auto *C = dyn_cast(I->getOperand(1))) { + Value *Xor = Builder.CreateXor(I->getOperand(0), ConstantExpr::getNot(C)); + return Builder.CreateAdd(Xor, ConstantInt::get(Xor->getType(), 1), + I->getName() + ".neg"); + } + return nullptr; + case Instruction::Mul: { + // `mul` is negatible if one of its operands is negatible. + Value *NegatedOp, *OtherOp; + // First try the second operand, in case it's a constant it will be best to + // just invert it instead of sinking the `neg` deeper. + if (Value *NegOp1 = visit(I->getOperand(1), Depth + 1)) { + NegatedOp = NegOp1; + OtherOp = I->getOperand(0); + } else if (Value *NegOp0 = visit(I->getOperand(0), Depth + 1)) { + NegatedOp = NegOp0; + OtherOp = I->getOperand(1); + } else + // Can't negate either of them. + return nullptr; + return Builder.CreateMul(NegatedOp, OtherOp, I->getName() + ".neg"); + } + default: + return nullptr; // Don't know, likely not negatible for free. + } + + llvm_unreachable("Can't get here. We always return from switch."); +}; + +LLVM_NODISCARD Optional Negator::run(Value *Root) { + Value *Negated = visit(Root, /*Depth=*/0); + if (!Negated) { + // We must cleanup newly-inserted instructions, to avoid any potential + // endless combine looping. + llvm::for_each(llvm::reverse(NewInstructions), + [&](Instruction *I) { I->eraseFromParent(); }); + return llvm::None; + } + return std::make_pair(ArrayRef(NewInstructions), Negated); +}; + +LLVM_NODISCARD Value *Negator::Negate(bool LHSIsZero, Value *Root, + InstCombiner &IC) { + ++NegatorTotalNegationsAttempted; + LLVM_DEBUG(dbgs() << "Negator: attempting to sink negation into " << *Root + << "\n"); + + if (!NegatorEnabled || !DebugCounter::shouldExecute(NegatorCounter)) + return nullptr; + + Negator N(Root->getContext(), IC.getDataLayout(), LHSIsZero); + Optional Res = N.run(Root); + if (!Res) { // Negation failed. + LLVM_DEBUG(dbgs() << "Negator: failed to sink negation into " << *Root + << "\n"); + return nullptr; + } + + LLVM_DEBUG(dbgs() << "Negator: successfully sunk negation into " << *Root + << "\n NEW: " << *Res->second << "\n"); + ++NegatorNumTreesNegated; + + // We must temporarily unset the 'current' insertion point and DebugLoc of the + // InstCombine's IRBuilder so that it won't interfere with the ones we have + // already specified when producing negated instructions. + InstCombiner::BuilderTy::InsertPointGuard Guard(IC.Builder); + IC.Builder.ClearInsertionPoint(); + IC.Builder.SetCurrentDebugLocation(DebugLoc()); + + // And finally, we must add newly-created instructions into the InstCombine's + // worklist (in a proper order!) so it can attempt to combine them. + LLVM_DEBUG(dbgs() << "Negator: Propagating " << Res->first.size() + << " instrs to InstCombine\n"); + NegatorMaxInstructionsCreated.updateMax(Res->first.size()); + NegatorNumInstructionsNegatedSuccess += Res->first.size(); + + // They are in def-use order, so nothing fancy, just insert them in order. + llvm::for_each(Res->first, [&](Instruction *I) { IC.Builder.Insert(I); }); + + // And return the new root. + return Res->second; +}; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1401,8 +1401,9 @@ if (Instruction *NewSel = canonicalizeMinMaxWithConstant(SI, *ICI, *this)) return NewSel; - if (Instruction *NewAbs = canonicalizeAbsNabs(SI, *ICI, *this)) - return NewAbs; + // FIXME: interferes with Negator. + // if (Instruction *NewAbs = canonicalizeAbsNabs(SI, *ICI, *this)) + // return NewAbs; if (Instruction *NewAbs = canonicalizeClampLike(SI, *ICI, Builder)) return NewAbs; diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -853,120 +853,6 @@ return nullptr; } -/// Get negated V (that is 0-V) without increasing instruction count, -/// assuming that the original V will become unused. -Value *InstCombiner::freelyNegateValue(Value *V) { - if (Value *NegV = dyn_castNegVal(V)) - return NegV; - - Instruction *I = dyn_cast(V); - if (!I) - return nullptr; - - unsigned BitWidth = I->getType()->getScalarSizeInBits(); - switch (I->getOpcode()) { - // 0-(zext i1 A) => sext i1 A - case Instruction::ZExt: - if (I->getOperand(0)->getType()->isIntOrIntVectorTy(1)) - return Builder.CreateSExtOrBitCast( - I->getOperand(0), I->getType(), I->getName() + ".neg"); - return nullptr; - - // 0-(sext i1 A) => zext i1 A - case Instruction::SExt: - if (I->getOperand(0)->getType()->isIntOrIntVectorTy(1)) - return Builder.CreateZExtOrBitCast( - I->getOperand(0), I->getType(), I->getName() + ".neg"); - return nullptr; - - // 0-(A lshr (BW-1)) => A ashr (BW-1) - case Instruction::LShr: - if (match(I->getOperand(1), m_SpecificInt(BitWidth - 1))) - return Builder.CreateAShr( - I->getOperand(0), I->getOperand(1), - I->getName() + ".neg", cast(I)->isExact()); - return nullptr; - - // 0-(A ashr (BW-1)) => A lshr (BW-1) - case Instruction::AShr: - if (match(I->getOperand(1), m_SpecificInt(BitWidth - 1))) - return Builder.CreateLShr( - I->getOperand(0), I->getOperand(1), - I->getName() + ".neg", cast(I)->isExact()); - return nullptr; - - // Negation is equivalent to bitwise-not + 1. - case Instruction::Xor: { - // Special case for negate of 'not' - replace with increment: - // 0 - (~A) => ((A ^ -1) ^ -1) + 1 => A + 1 - Value *A; - if (match(I, m_Not(m_Value(A)))) - return Builder.CreateAdd(A, ConstantInt::get(A->getType(), 1), - I->getName() + ".neg"); - - // General case xor (not a 'not') requires creating a new xor, so this has a - // one-use limitation: - // 0 - (A ^ C) => ((A ^ C) ^ -1) + 1 => A ^ ~C + 1 - Constant *C; - if (match(I, m_OneUse(m_Xor(m_Value(A), m_Constant(C))))) { - Value *Xor = Builder.CreateXor(A, ConstantExpr::getNot(C)); - return Builder.CreateAdd(Xor, ConstantInt::get(Xor->getType(), 1), - I->getName() + ".neg"); - } - return nullptr; - } - - default: - break; - } - - // TODO: The "sub" pattern below could also be applied without the one-use - // restriction. Not allowing it for now in line with existing behavior. - if (!I->hasOneUse()) - return nullptr; - - switch (I->getOpcode()) { - // 0-(A-B) => B-A - case Instruction::Sub: - return Builder.CreateSub( - I->getOperand(1), I->getOperand(0), I->getName() + ".neg"); - - // 0-(A sdiv C) => A sdiv (0-C) provided the negation doesn't overflow. - case Instruction::SDiv: { - Constant *C = dyn_cast(I->getOperand(1)); - if (C && !C->containsUndefElement() && C->isNotMinSignedValue() && - C->isNotOneValue()) - return Builder.CreateSDiv(I->getOperand(0), ConstantExpr::getNeg(C), - I->getName() + ".neg", cast(I)->isExact()); - return nullptr; - } - - // 0-(A< (0-A)<getOperand(0))) - return Builder.CreateShl(NegA, I->getOperand(1), I->getName() + ".neg"); - return nullptr; - - // 0-(trunc A) => trunc (0-A) - case Instruction::Trunc: - if (Value *NegA = freelyNegateValue(I->getOperand(0))) - return Builder.CreateTrunc(NegA, I->getType(), I->getName() + ".neg"); - return nullptr; - - // 0-(A*B) => (0-A)*B - // 0-(A*B) => A*(0-B) - case Instruction::Mul: - if (Value *NegA = freelyNegateValue(I->getOperand(0))) - return Builder.CreateMul(NegA, I->getOperand(1), V->getName() + ".neg"); - if (Value *NegB = freelyNegateValue(I->getOperand(1))) - return Builder.CreateMul(I->getOperand(0), NegB, V->getName() + ".neg"); - return nullptr; - - default: - return nullptr; - } -} - static Value *foldOperationIntoSelectOperand(Instruction &I, Value *SO, InstCombiner::BuilderTy &Builder) { if (auto *Cast = dyn_cast(&I)) diff --git a/llvm/test/Transforms/InstCombine/abs-1.ll b/llvm/test/Transforms/InstCombine/abs-1.ll --- a/llvm/test/Transforms/InstCombine/abs-1.ll +++ b/llvm/test/Transforms/InstCombine/abs-1.ll @@ -47,9 +47,9 @@ define i8 @abs_canonical_1(i8 %x) { ; CHECK-LABEL: @abs_canonical_1( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 0 ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i8 [[NEG]], i8 [[X]] +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i8 [[X]], i8 [[NEG]] ; CHECK-NEXT: ret i8 [[ABS]] ; %cmp = icmp sgt i8 %x, 0 @@ -62,9 +62,9 @@ define <2 x i8> @abs_canonical_2(<2 x i8> %x) { ; CHECK-LABEL: @abs_canonical_2( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]] -; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[NEG]], <2 x i8> [[X]] +; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> [[NEG]] ; CHECK-NEXT: ret <2 x i8> [[ABS]] ; %cmp = icmp sgt <2 x i8> %x, @@ -77,9 +77,9 @@ define <2 x i8> @abs_canonical_2_vec_undef_elts(<2 x i8> %x) { ; CHECK-LABEL: @abs_canonical_2_vec_undef_elts( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]] -; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[NEG]], <2 x i8> [[X]] +; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> [[NEG]] ; CHECK-NEXT: ret <2 x i8> [[ABS]] ; %cmp = icmp sgt <2 x i8> %x, @@ -105,7 +105,7 @@ define i8 @abs_canonical_4(i8 %x) { ; CHECK-LABEL: @abs_canonical_4( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 1 ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X]] ; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i8 [[NEG]], i8 [[X]] ; CHECK-NEXT: ret i8 [[ABS]] @@ -118,10 +118,10 @@ define i32 @abs_canonical_5(i8 %x) { ; CHECK-LABEL: @abs_canonical_5( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 0 ; CHECK-NEXT: [[CONV:%.*]] = sext i8 [[X]] to i32 ; CHECK-NEXT: [[NEG:%.*]] = sub nsw i32 0, [[CONV]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[NEG]], i32 [[CONV]] +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[CONV]], i32 [[NEG]] ; CHECK-NEXT: ret i32 [[ABS]] ; %cmp = icmp sgt i8 %x, 0 @@ -134,9 +134,9 @@ define i32 @abs_canonical_6(i32 %a, i32 %b) { ; CHECK-LABEL: @abs_canonical_6( ; CHECK-NEXT: [[T1:%.*]] = sub i32 [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[T1]], 0 -; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[T1]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[TMP1]], i32 [[T1]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[T1]], -1 +; CHECK-NEXT: [[T2:%.*]] = sub i32 [[B]], [[A]] +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[T1]], i32 [[T2]] ; CHECK-NEXT: ret i32 [[ABS]] ; %t1 = sub i32 %a, %b @@ -149,9 +149,9 @@ define <2 x i8> @abs_canonical_7(<2 x i8> %a, <2 x i8 > %b) { ; CHECK-LABEL: @abs_canonical_7( ; CHECK-NEXT: [[T1:%.*]] = sub <2 x i8> [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[T1]], zeroinitializer -; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i8> zeroinitializer, [[T1]] -; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[TMP1]], <2 x i8> [[T1]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[T1]], +; CHECK-NEXT: [[T2:%.*]] = sub <2 x i8> [[B]], [[A]] +; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[T1]], <2 x i8> [[T2]] ; CHECK-NEXT: ret <2 x i8> [[ABS]] ; @@ -165,8 +165,8 @@ define i32 @abs_canonical_8(i32 %a) { ; CHECK-LABEL: @abs_canonical_8( ; CHECK-NEXT: [[T:%.*]] = sub i32 0, [[A:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0 -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[T]], i32 [[A]] +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[T]], 0 +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[T]] ; CHECK-NEXT: ret i32 [[ABS]] ; %t = sub i32 0, %a @@ -194,10 +194,10 @@ define i32 @abs_canonical_10(i32 %a, i32 %b) { ; CHECK-LABEL: @abs_canonical_10( -; CHECK-NEXT: [[T1:%.*]] = sub i32 [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[T1]], 0 -; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[T1]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[TMP1]], i32 [[T1]] +; CHECK-NEXT: [[T2:%.*]] = sub i32 [[B:%.*]], [[A:%.*]] +; CHECK-NEXT: [[T1:%.*]] = sub i32 [[A]], [[B]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[T1]], -1 +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[T1]], i32 [[T2]] ; CHECK-NEXT: ret i32 [[ABS]] ; %t2 = sub i32 %b, %a @@ -211,9 +211,9 @@ define i8 @nabs_canonical_1(i8 %x) { ; CHECK-LABEL: @nabs_canonical_1( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 0 ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i8 [[X]], i8 [[NEG]] +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i8 [[NEG]], i8 [[X]] ; CHECK-NEXT: ret i8 [[ABS]] ; %cmp = icmp sgt i8 %x, 0 @@ -226,9 +226,9 @@ define <2 x i8> @nabs_canonical_2(<2 x i8> %x) { ; CHECK-LABEL: @nabs_canonical_2( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]] -; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> [[NEG]] +; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[NEG]], <2 x i8> [[X]] ; CHECK-NEXT: ret <2 x i8> [[ABS]] ; %cmp = icmp sgt <2 x i8> %x, @@ -241,9 +241,9 @@ define <2 x i8> @nabs_canonical_2_vec_undef_elts(<2 x i8> %x) { ; CHECK-LABEL: @nabs_canonical_2_vec_undef_elts( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]] -; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> [[NEG]] +; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[NEG]], <2 x i8> [[X]] ; CHECK-NEXT: ret <2 x i8> [[ABS]] ; %cmp = icmp sgt <2 x i8> %x, @@ -269,7 +269,7 @@ define i8 @nabs_canonical_4(i8 %x) { ; CHECK-LABEL: @nabs_canonical_4( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 1 ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X]] ; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i8 [[X]], i8 [[NEG]] ; CHECK-NEXT: ret i8 [[ABS]] @@ -282,10 +282,10 @@ define i32 @nabs_canonical_5(i8 %x) { ; CHECK-LABEL: @nabs_canonical_5( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 0 ; CHECK-NEXT: [[CONV:%.*]] = sext i8 [[X]] to i32 ; CHECK-NEXT: [[NEG:%.*]] = sub nsw i32 0, [[CONV]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[CONV]], i32 [[NEG]] +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[NEG]], i32 [[CONV]] ; CHECK-NEXT: ret i32 [[ABS]] ; %cmp = icmp sgt i8 %x, 0 @@ -298,9 +298,9 @@ define i32 @nabs_canonical_6(i32 %a, i32 %b) { ; CHECK-LABEL: @nabs_canonical_6( ; CHECK-NEXT: [[T1:%.*]] = sub i32 [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[T1]], 0 -; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[T1]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[T1]], i32 [[TMP1]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[T1]], -1 +; CHECK-NEXT: [[T2:%.*]] = sub i32 [[B]], [[A]] +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[T2]], i32 [[T1]] ; CHECK-NEXT: ret i32 [[ABS]] ; %t1 = sub i32 %a, %b @@ -313,9 +313,9 @@ define <2 x i8> @nabs_canonical_7(<2 x i8> %a, <2 x i8 > %b) { ; CHECK-LABEL: @nabs_canonical_7( ; CHECK-NEXT: [[T1:%.*]] = sub <2 x i8> [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[T1]], zeroinitializer -; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i8> zeroinitializer, [[T1]] -; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[T1]], <2 x i8> [[TMP1]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[T1]], +; CHECK-NEXT: [[T2:%.*]] = sub <2 x i8> [[B]], [[A]] +; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[T2]], <2 x i8> [[T1]] ; CHECK-NEXT: ret <2 x i8> [[ABS]] ; %t1 = sub <2 x i8> %a, %b @@ -328,8 +328,8 @@ define i32 @nabs_canonical_8(i32 %a) { ; CHECK-LABEL: @nabs_canonical_8( ; CHECK-NEXT: [[T:%.*]] = sub i32 0, [[A:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0 -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[T]] +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[T]], 0 +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[T]], i32 [[A]] ; CHECK-NEXT: ret i32 [[ABS]] ; %t = sub i32 0, %a @@ -357,10 +357,10 @@ define i32 @nabs_canonical_10(i32 %a, i32 %b) { ; CHECK-LABEL: @nabs_canonical_10( -; CHECK-NEXT: [[T1:%.*]] = sub i32 [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[T1]], 0 -; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[T1]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[T1]], i32 [[TMP1]] +; CHECK-NEXT: [[T2:%.*]] = sub i32 [[B:%.*]], [[A:%.*]] +; CHECK-NEXT: [[T1:%.*]] = sub i32 [[A]], [[B]] +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[T1]], 1 +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[T1]], i32 [[T2]] ; CHECK-NEXT: ret i32 [[ABS]] ; %t2 = sub i32 %b, %a @@ -534,8 +534,8 @@ ; CHECK-LABEL: @negate_abs( ; CHECK-NEXT: [[N:%.*]] = sub i8 0, [[X:%.*]] ; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X]], 0 -; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i8 [[X]], i8 [[N]] -; CHECK-NEXT: ret i8 [[S]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C]], i8 [[X]], i8 [[N]] +; CHECK-NEXT: ret i8 [[TMP1]] ; %n = sub i8 0, %x %c = icmp slt i8 %x, 0 @@ -548,8 +548,8 @@ ; CHECK-LABEL: @negate_nabs( ; CHECK-NEXT: [[N:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]] ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i8> [[X]], zeroinitializer -; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[C]], <2 x i8> [[N]], <2 x i8> [[X]] -; CHECK-NEXT: ret <2 x i8> [[S]] +; CHECK-NEXT: [[TMP1:%.*]] = select <2 x i1> [[C]], <2 x i8> [[N]], <2 x i8> [[X]] +; CHECK-NEXT: ret <2 x i8> [[TMP1]] ; %n = sub <2 x i8> zeroinitializer, %x %c = icmp slt <2 x i8> %x, zeroinitializer @@ -573,8 +573,8 @@ ; CHECK-LABEL: @abs_swapped( ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]] ; CHECK-NEXT: call void @extra_use(i8 [[NEG]]) -; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A]], 0 -; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[NEG]], i8 [[A]] +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A]], 0 +; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]] ; CHECK-NEXT: ret i8 [[M1]] ; %neg = sub i8 0, %a @@ -588,8 +588,8 @@ ; CHECK-LABEL: @nabs_swapped( ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]] ; CHECK-NEXT: call void @extra_use(i8 [[NEG]]) -; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i8 [[A]], 0 -; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[A]], i8 [[NEG]] +; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[A]], 0 +; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 [[A]] ; CHECK-NEXT: ret i8 [[M2]] ; %neg = sub i8 0, %a @@ -603,8 +603,8 @@ ; CHECK-LABEL: @abs_different_constants( ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]] ; CHECK-NEXT: call void @extra_use(i8 [[NEG]]) -; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A]], 0 -; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[NEG]], i8 [[A]] +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A]], -1 +; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]] ; CHECK-NEXT: ret i8 [[M1]] ; %neg = sub i8 0, %a @@ -618,8 +618,8 @@ ; CHECK-LABEL: @nabs_different_constants( ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]] ; CHECK-NEXT: call void @extra_use(i8 [[NEG]]) -; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i8 [[A]], 0 -; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[A]], i8 [[NEG]] +; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[A]], -1 +; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 [[A]] ; CHECK-NEXT: ret i8 [[M2]] ; %neg = sub i8 0, %a diff --git a/llvm/test/Transforms/InstCombine/abs_abs.ll b/llvm/test/Transforms/InstCombine/abs_abs.ll --- a/llvm/test/Transforms/InstCombine/abs_abs.ll +++ b/llvm/test/Transforms/InstCombine/abs_abs.ll @@ -3,9 +3,9 @@ define i32 @abs_abs_x01(i32 %x) { ; CHECK-LABEL: @abs_abs_x01( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, -1 @@ -19,9 +19,9 @@ define <2 x i32> @abs_abs_x01_vec(<2 x i32> %x) { ; CHECK-LABEL: @abs_abs_x01_vec( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]] +; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[X]], <2 x i32> [[SUB]] ; CHECK-NEXT: ret <2 x i32> [[COND]] ; %cmp = icmp sgt <2 x i32> %x, @@ -35,9 +35,9 @@ define i32 @abs_abs_x02(i32 %x) { ; CHECK-LABEL: @abs_abs_x02( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, 0 @@ -67,7 +67,7 @@ define i32 @abs_abs_x04(i32 %x) { ; CHECK-LABEL: @abs_abs_x04( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] @@ -83,7 +83,7 @@ define <2 x i32> @abs_abs_x04_vec(<2 x i32> %x) { ; CHECK-LABEL: @abs_abs_x04_vec( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X]] ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]] ; CHECK-NEXT: ret <2 x i32> [[COND]] @@ -99,9 +99,9 @@ define i32 @abs_abs_x05(i32 %x) { ; CHECK-LABEL: @abs_abs_x05( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, -1 @@ -115,9 +115,9 @@ define i32 @abs_abs_x06(i32 %x) { ; CHECK-LABEL: @abs_abs_x06( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, 0 @@ -147,7 +147,7 @@ define i32 @abs_abs_x08(i32 %x) { ; CHECK-LABEL: @abs_abs_x08( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] @@ -163,9 +163,9 @@ define i32 @abs_abs_x09(i32 %x) { ; CHECK-LABEL: @abs_abs_x09( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, -1 @@ -179,9 +179,9 @@ define i32 @abs_abs_x10(i32 %x) { ; CHECK-LABEL: @abs_abs_x10( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, 0 @@ -211,7 +211,7 @@ define i32 @abs_abs_x12(i32 %x) { ; CHECK-LABEL: @abs_abs_x12( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] @@ -227,9 +227,9 @@ define i32 @abs_abs_x13(i32 %x) { ; CHECK-LABEL: @abs_abs_x13( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, -1 @@ -243,9 +243,9 @@ define i32 @abs_abs_x14(i32 %x) { ; CHECK-LABEL: @abs_abs_x14( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, 0 @@ -275,7 +275,7 @@ define i32 @abs_abs_x16(i32 %x) { ; CHECK-LABEL: @abs_abs_x16( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] @@ -293,7 +293,7 @@ define i32 @abs_abs_x17(i32 %x) { ; CHECK-LABEL: @abs_abs_x17( ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 1 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] ; @@ -310,9 +310,9 @@ define i32 @abs_abs_x18(i32 %x, i32 %y) { ; CHECK-LABEL: @abs_abs_x18( ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0 -; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[NEGA]], i32 [[A]] +; CHECK-NEXT: [[B:%.*]] = sub nsw i32 [[Y]], [[X]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A]], -1 +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[B]] ; CHECK-NEXT: ret i32 [[COND]] ; %a = sub nsw i32 %x, %y @@ -329,7 +329,7 @@ define <2 x i32> @abs_abs_x02_vec(<2 x i32> %x) { ; CHECK-LABEL: @abs_abs_x02_vec( ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]] ; CHECK-NEXT: ret <2 x i32> [[COND]] ; @@ -346,9 +346,9 @@ define <2 x i32> @abs_abs_x03_vec(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @abs_abs_x03_vec( ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[A]], zeroinitializer -; CHECK-NEXT: [[NEGA:%.*]] = sub <2 x i32> zeroinitializer, [[A]] -; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[NEGA]], <2 x i32> [[A]] +; CHECK-NEXT: [[B:%.*]] = sub nsw <2 x i32> [[Y]], [[X]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[A]], +; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[A]], <2 x i32> [[B]] ; CHECK-NEXT: ret <2 x i32> [[COND]] ; %a = sub nsw <2 x i32> %x, %y @@ -363,9 +363,9 @@ define i32 @nabs_nabs_x01(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x01( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, -1 @@ -379,9 +379,9 @@ define i32 @nabs_nabs_x02(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x02( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, 0 @@ -411,7 +411,7 @@ define i32 @nabs_nabs_x04(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x04( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] @@ -427,9 +427,9 @@ define i32 @nabs_nabs_x05(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x05( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, -1 @@ -443,9 +443,9 @@ define i32 @nabs_nabs_x06(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x06( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, 0 @@ -475,7 +475,7 @@ define i32 @nabs_nabs_x08(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x08( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] @@ -491,9 +491,9 @@ define i32 @nabs_nabs_x09(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x09( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, -1 @@ -507,9 +507,9 @@ define i32 @nabs_nabs_x10(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x10( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, 0 @@ -539,7 +539,7 @@ define i32 @nabs_nabs_x12(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x12( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] @@ -555,9 +555,9 @@ define i32 @nabs_nabs_x13(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x13( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, -1 @@ -571,9 +571,9 @@ define i32 @nabs_nabs_x14(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x14( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, 0 @@ -603,7 +603,7 @@ define i32 @nabs_nabs_x16(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x16( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] @@ -621,7 +621,7 @@ define i32 @nabs_nabs_x17(i32 %x) { ; CHECK-LABEL: @nabs_nabs_x17( ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 1 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND]] ; @@ -638,9 +638,9 @@ define i32 @nabs_nabs_x18(i32 %x, i32 %y) { ; CHECK-LABEL: @nabs_nabs_x18( ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0 -; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[NEGA]] +; CHECK-NEXT: [[B:%.*]] = sub nsw i32 [[Y]], [[X]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A]], -1 +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[B]], i32 [[A]] ; CHECK-NEXT: ret i32 [[COND]] ; %a = sub nsw i32 %x, %y @@ -657,7 +657,7 @@ define <2 x i32> @nabs_nabs_x01_vec(<2 x i32> %x) { ; CHECK-LABEL: @nabs_nabs_x01_vec( ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[X]], <2 x i32> [[SUB]] ; CHECK-NEXT: ret <2 x i32> [[COND]] ; @@ -674,9 +674,9 @@ define <2 x i32> @nabs_nabs_x02_vec(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @nabs_nabs_x02_vec( ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[A]], zeroinitializer -; CHECK-NEXT: [[NEGA:%.*]] = sub <2 x i32> zeroinitializer, [[A]] -; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[A]], <2 x i32> [[NEGA]] +; CHECK-NEXT: [[B:%.*]] = sub nsw <2 x i32> [[Y]], [[X]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[A]], +; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[B]], <2 x i32> [[A]] ; CHECK-NEXT: ret <2 x i32> [[COND]] ; %a = sub nsw <2 x i32> %x, %y @@ -691,9 +691,9 @@ define i32 @abs_nabs_x01(i32 %x) { ; CHECK-LABEL: @abs_nabs_x01( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND1]] ; %cmp = icmp sgt i32 %x, -1 @@ -707,9 +707,9 @@ define i32 @abs_nabs_x02(i32 %x) { ; CHECK-LABEL: @abs_nabs_x02( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND1]] ; %cmp = icmp sgt i32 %x, 0 @@ -739,7 +739,7 @@ define i32 @abs_nabs_x04(i32 %x) { ; CHECK-LABEL: @abs_nabs_x04( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND1]] @@ -755,10 +755,10 @@ define i32 @abs_nabs_x05(i32 %x) { ; CHECK-LABEL: @abs_nabs_x05( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp sgt i32 %x, -1 %sub = sub nsw i32 0, %x @@ -771,10 +771,10 @@ define i32 @abs_nabs_x06(i32 %x) { ; CHECK-LABEL: @abs_nabs_x06( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp sgt i32 %x, 0 %sub = sub nsw i32 0, %x @@ -789,8 +789,8 @@ ; CHECK-LABEL: @abs_nabs_x07( ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp slt i32 %x, 0 %sub = sub nsw i32 0, %x @@ -803,10 +803,10 @@ define i32 @abs_nabs_x08(i32 %x) { ; CHECK-LABEL: @abs_nabs_x08( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp slt i32 %x, 1 %sub = sub nsw i32 0, %x @@ -819,9 +819,9 @@ define i32 @abs_nabs_x09(i32 %x) { ; CHECK-LABEL: @abs_nabs_x09( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND1]] ; %cmp = icmp sgt i32 %x, -1 @@ -835,9 +835,9 @@ define i32 @abs_nabs_x10(i32 %x) { ; CHECK-LABEL: @abs_nabs_x10( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND1]] ; %cmp = icmp sgt i32 %x, 0 @@ -867,7 +867,7 @@ define i32 @abs_nabs_x12(i32 %x) { ; CHECK-LABEL: @abs_nabs_x12( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND1]] @@ -883,10 +883,10 @@ define i32 @abs_nabs_x13(i32 %x) { ; CHECK-LABEL: @abs_nabs_x13( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp sgt i32 %x, -1 %sub = sub nsw i32 0, %x @@ -899,10 +899,10 @@ define i32 @abs_nabs_x14(i32 %x) { ; CHECK-LABEL: @abs_nabs_x14( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp sgt i32 %x, 0 %sub = sub nsw i32 0, %x @@ -917,8 +917,8 @@ ; CHECK-LABEL: @abs_nabs_x15( ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp slt i32 %x, 0 %sub = sub nsw i32 0, %x @@ -931,10 +931,10 @@ define i32 @abs_nabs_x16(i32 %x) { ; CHECK-LABEL: @abs_nabs_x16( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp slt i32 %x, 1 %sub = sub nsw i32 0, %x @@ -949,9 +949,9 @@ define i32 @abs_nabs_x17(i32 %x) { ; CHECK-LABEL: @abs_nabs_x17( ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 0 -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] -; CHECK-NEXT: ret i32 [[COND]] +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 1 +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: ret i32 [[COND1]] ; %sub = sub nsw i32 0, %x %cmp = icmp sgt i32 %sub, -1 @@ -966,10 +966,10 @@ define i32 @abs_nabs_x18(i32 %x, i32 %y) { ; CHECK-LABEL: @abs_nabs_x18( ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0 -; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[NEGA]], i32 [[A]] -; CHECK-NEXT: ret i32 [[COND]] +; CHECK-NEXT: [[B:%.*]] = sub nsw i32 [[Y]], [[X]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A]], -1 +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[B]] +; CHECK-NEXT: ret i32 [[COND1]] ; %a = sub nsw i32 %x, %y %b = sub nsw i32 %y, %x @@ -985,9 +985,9 @@ define <2 x i32> @abs_nabs_x01_vec(<2 x i32> %x) { ; CHECK-LABEL: @abs_nabs_x01_vec( ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer -; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]] -; CHECK-NEXT: ret <2 x i32> [[COND]] +; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], +; CHECK-NEXT: [[COND1:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]] +; CHECK-NEXT: ret <2 x i32> [[COND1]] ; %sub = sub nsw <2 x i32> zeroinitializer, %x %cmp = icmp sgt <2 x i32> %sub, @@ -1002,10 +1002,10 @@ define <2 x i32> @abs_nabs_x02_vec(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @abs_nabs_x02_vec( ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[A]], zeroinitializer -; CHECK-NEXT: [[NEGA:%.*]] = sub <2 x i32> zeroinitializer, [[A]] -; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[NEGA]], <2 x i32> [[A]] -; CHECK-NEXT: ret <2 x i32> [[COND]] +; CHECK-NEXT: [[B:%.*]] = sub nsw <2 x i32> [[Y]], [[X]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[A]], +; CHECK-NEXT: [[COND1:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[A]], <2 x i32> [[B]] +; CHECK-NEXT: ret <2 x i32> [[COND1]] ; %a = sub nsw <2 x i32> %x, %y %b = sub nsw <2 x i32> %y, %x @@ -1019,10 +1019,10 @@ define i32 @nabs_abs_x01(i32 %x) { ; CHECK-LABEL: @nabs_abs_x01( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp sgt i32 %x, -1 %sub = sub nsw i32 0, %x @@ -1035,10 +1035,10 @@ define i32 @nabs_abs_x02(i32 %x) { ; CHECK-LABEL: @nabs_abs_x02( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp sgt i32 %x, 0 %sub = sub nsw i32 0, %x @@ -1053,8 +1053,8 @@ ; CHECK-LABEL: @nabs_abs_x03( ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp slt i32 %x, 0 %sub = sub nsw i32 0, %x @@ -1067,10 +1067,10 @@ define i32 @nabs_abs_x04(i32 %x) { ; CHECK-LABEL: @nabs_abs_x04( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] -; CHECK-NEXT: ret i32 [[COND1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp slt i32 %x, 1 %sub = sub nsw i32 0, %x @@ -1083,9 +1083,9 @@ define i32 @nabs_abs_x05(i32 %x) { ; CHECK-LABEL: @nabs_abs_x05( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND1]] ; %cmp = icmp sgt i32 %x, -1 @@ -1099,9 +1099,9 @@ define i32 @nabs_abs_x06(i32 %x) { ; CHECK-LABEL: @nabs_abs_x06( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND1]] ; %cmp = icmp sgt i32 %x, 0 @@ -1131,7 +1131,7 @@ define i32 @nabs_abs_x08(i32 %x) { ; CHECK-LABEL: @nabs_abs_x08( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND1]] @@ -1147,10 +1147,10 @@ define i32 @nabs_abs_x09(i32 %x) { ; CHECK-LABEL: @nabs_abs_x09( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] -; CHECK-NEXT: ret i32 [[COND]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp sgt i32 %x, -1 %sub = sub nsw i32 0, %x @@ -1163,10 +1163,10 @@ define i32 @nabs_abs_x10(i32 %x) { ; CHECK-LABEL: @nabs_abs_x10( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] -; CHECK-NEXT: ret i32 [[COND]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp sgt i32 %x, 0 %sub = sub nsw i32 0, %x @@ -1181,8 +1181,8 @@ ; CHECK-LABEL: @nabs_abs_x11( ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] -; CHECK-NEXT: ret i32 [[COND]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp slt i32 %x, 0 %sub = sub nsw i32 0, %x @@ -1195,10 +1195,10 @@ define i32 @nabs_abs_x12(i32 %x) { ; CHECK-LABEL: @nabs_abs_x12( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] -; CHECK-NEXT: ret i32 [[COND]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %cmp = icmp slt i32 %x, 1 %sub = sub nsw i32 0, %x @@ -1211,9 +1211,9 @@ define i32 @nabs_abs_x13(i32 %x) { ; CHECK-LABEL: @nabs_abs_x13( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND1]] ; %cmp = icmp sgt i32 %x, -1 @@ -1227,9 +1227,9 @@ define i32 @nabs_abs_x14(i32 %x) { ; CHECK-LABEL: @nabs_abs_x14( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 [[X]] ; CHECK-NEXT: ret i32 [[COND1]] ; %cmp = icmp sgt i32 %x, 0 @@ -1259,7 +1259,7 @@ define i32 @nabs_abs_x16(i32 %x) { ; CHECK-LABEL: @nabs_abs_x16( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[COND1]] @@ -1277,9 +1277,9 @@ define i32 @nabs_abs_x17(i32 %x) { ; CHECK-LABEL: @nabs_abs_x17( ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 0 -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] -; CHECK-NEXT: ret i32 [[COND]] +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X]], 1 +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]] +; CHECK-NEXT: ret i32 [[TMP1]] ; %sub = sub nsw i32 0, %x %cmp = icmp sgt i32 %sub, -1 @@ -1294,10 +1294,10 @@ define i32 @nabs_abs_x18(i32 %x, i32 %y) { ; CHECK-LABEL: @nabs_abs_x18( ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A]], 0 -; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]] -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[A]], i32 [[NEGA]] -; CHECK-NEXT: ret i32 [[COND]] +; CHECK-NEXT: [[B:%.*]] = sub nsw i32 [[Y]], [[X]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A]], -1 +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[B]], i32 [[A]] +; CHECK-NEXT: ret i32 [[COND1]] ; %a = sub nsw i32 %x, %y %b = sub nsw i32 %y, %x @@ -1313,9 +1313,9 @@ define <2 x i32> @nabs_abs_x01_vec(<2 x i32> %x) { ; CHECK-LABEL: @nabs_abs_x01_vec( ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer -; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[X]], <2 x i32> [[SUB]] -; CHECK-NEXT: ret <2 x i32> [[COND]] +; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], +; CHECK-NEXT: [[TMP1:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[X]], <2 x i32> [[SUB]] +; CHECK-NEXT: ret <2 x i32> [[TMP1]] ; %sub = sub nsw <2 x i32> zeroinitializer, %x %cmp = icmp sgt <2 x i32> %sub, @@ -1330,10 +1330,10 @@ define <2 x i32> @nabs_abs_x02_vec(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @nabs_abs_x02_vec( ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[A]], zeroinitializer -; CHECK-NEXT: [[NEGA:%.*]] = sub <2 x i32> zeroinitializer, [[A]] -; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[A]], <2 x i32> [[NEGA]] -; CHECK-NEXT: ret <2 x i32> [[COND]] +; CHECK-NEXT: [[B:%.*]] = sub nsw <2 x i32> [[Y]], [[X]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[A]], +; CHECK-NEXT: [[COND1:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[B]], <2 x i32> [[A]] +; CHECK-NEXT: ret <2 x i32> [[COND1]] ; %a = sub nsw <2 x i32> %x, %y %b = sub nsw <2 x i32> %y, %x diff --git a/llvm/test/Transforms/InstCombine/and-or-icmps.ll b/llvm/test/Transforms/InstCombine/and-or-icmps.ll --- a/llvm/test/Transforms/InstCombine/and-or-icmps.ll +++ b/llvm/test/Transforms/InstCombine/and-or-icmps.ll @@ -208,12 +208,20 @@ ; CHECK-LABEL: @simplify_before_foldAndOfICmps( ; CHECK-NEXT: [[A8:%.*]] = alloca i16, align 2 ; CHECK-NEXT: [[L7:%.*]] = load i16, i16* [[A8]], align 2 -; CHECK-NEXT: [[C10:%.*]] = icmp ult i16 [[L7]], 2 +; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i16 [[L7]], -1 +; CHECK-NEXT: [[B11:%.*]] = zext i1 [[TMP1]] to i16 +; CHECK-NEXT: [[C10:%.*]] = icmp ugt i16 [[L7]], [[B11]] +; CHECK-NEXT: [[C5:%.*]] = icmp slt i16 [[L7]], 1 +; CHECK-NEXT: [[C11:%.*]] = icmp ne i16 [[L7]], 0 ; CHECK-NEXT: [[C7:%.*]] = icmp slt i16 [[L7]], 0 -; CHECK-NEXT: [[C18:%.*]] = or i1 [[C7]], [[C10]] -; CHECK-NEXT: [[L7_LOBIT:%.*]] = ashr i16 [[L7]], 15 -; CHECK-NEXT: [[TMP1:%.*]] = sext i16 [[L7_LOBIT]] to i64 -; CHECK-NEXT: [[G26:%.*]] = getelementptr i1, i1* null, i64 [[TMP1]] +; CHECK-NEXT: [[B15:%.*]] = xor i1 [[C7]], [[C10]] +; CHECK-NEXT: [[B19:%.*]] = xor i1 [[C11]], [[B15]] +; CHECK-NEXT: [[TMP2:%.*]] = and i1 [[C10]], [[C5]] +; CHECK-NEXT: [[C3:%.*]] = and i1 [[TMP2]], [[B19]] +; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[C10]], true +; CHECK-NEXT: [[C18:%.*]] = or i1 [[C7]], [[TMP3]] +; CHECK-NEXT: [[TMP4:%.*]] = sext i1 [[C3]] to i64 +; CHECK-NEXT: [[G26:%.*]] = getelementptr i1, i1* null, i64 [[TMP4]] ; CHECK-NEXT: store i16 [[L7]], i16* undef, align 2 ; CHECK-NEXT: store i1 [[C18]], i1* undef, align 1 ; CHECK-NEXT: store i1* [[G26]], i1** undef, align 8 diff --git a/llvm/test/Transforms/InstCombine/cttz-abs.ll b/llvm/test/Transforms/InstCombine/cttz-abs.ll --- a/llvm/test/Transforms/InstCombine/cttz-abs.ll +++ b/llvm/test/Transforms/InstCombine/cttz-abs.ll @@ -105,7 +105,7 @@ define i32 @cttz_abs_multiuse(i32 %x) { ; CHECK-LABEL: @cttz_abs_multiuse( -; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[S:%.*]] = sub i32 0, [[X]] ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[S]], i32 [[X]] ; CHECK-NEXT: call void @use_abs(i32 [[D]]) @@ -122,7 +122,7 @@ define i32 @cttz_nabs_multiuse(i32 %x) { ; CHECK-LABEL: @cttz_nabs_multiuse( -; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 0 +; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 1 ; CHECK-NEXT: [[S:%.*]] = sub i32 0, [[X]] ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[S]] ; CHECK-NEXT: call void @use_abs(i32 [[D]]) diff --git a/llvm/test/Transforms/InstCombine/fold-sub-of-not-to-inc-of-add.ll b/llvm/test/Transforms/InstCombine/fold-sub-of-not-to-inc-of-add.ll --- a/llvm/test/Transforms/InstCombine/fold-sub-of-not-to-inc-of-add.ll +++ b/llvm/test/Transforms/InstCombine/fold-sub-of-not-to-inc-of-add.ll @@ -13,8 +13,8 @@ define i32 @p0_scalar(i32 %x, i32 %y) { ; CHECK-LABEL: @p0_scalar( -; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[Y:%.*]], 1 -; CHECK-NEXT: [[T1:%.*]] = add i32 [[TMP1]], [[X:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], 1 +; CHECK-NEXT: [[T1:%.*]] = add i32 [[TMP1]], [[Y:%.*]] ; CHECK-NEXT: ret i32 [[T1]] ; %t0 = xor i32 %x, -1 @@ -28,8 +28,8 @@ define <4 x i32> @p1_vector_splat(<4 x i32> %x, <4 x i32> %y) { ; CHECK-LABEL: @p1_vector_splat( -; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[Y:%.*]], -; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[TMP1]], [[X:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[X:%.*]], +; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[TMP1]], [[Y:%.*]] ; CHECK-NEXT: ret <4 x i32> [[T1]] ; %t0 = xor <4 x i32> %x, @@ -39,8 +39,8 @@ define <4 x i32> @p2_vector_undef(<4 x i32> %x, <4 x i32> %y) { ; CHECK-LABEL: @p2_vector_undef( -; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[Y:%.*]], -; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[TMP1]], [[X:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[X:%.*]], +; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[TMP1]], [[Y:%.*]] ; CHECK-NEXT: ret <4 x i32> [[T1]] ; %t0 = xor <4 x i32> %x, @@ -85,8 +85,8 @@ define i32 @n5_is_not_not(i32 %x, i32 %y) { ; CHECK-LABEL: @n5_is_not_not( -; CHECK-NEXT: [[T0:%.*]] = xor i32 [[X:%.*]], 2147483647 -; CHECK-NEXT: [[T1:%.*]] = sub i32 [[Y:%.*]], [[T0]] +; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], -2147483647 +; CHECK-NEXT: [[T1:%.*]] = add i32 [[TMP1]], [[Y:%.*]] ; CHECK-NEXT: ret i32 [[T1]] ; %t0 = xor i32 %x, 2147483647 ; not -1 diff --git a/llvm/test/Transforms/InstCombine/high-bit-signmask-with-trunc.ll b/llvm/test/Transforms/InstCombine/high-bit-signmask-with-trunc.ll --- a/llvm/test/Transforms/InstCombine/high-bit-signmask-with-trunc.ll +++ b/llvm/test/Transforms/InstCombine/high-bit-signmask-with-trunc.ll @@ -76,11 +76,11 @@ define i32 @t6(i64 %x) { ; CHECK-LABEL: @t6( -; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[TMP1:%.*]] = ashr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X]], 63 ; CHECK-NEXT: call void @use64(i64 [[T0]]) -; CHECK-NEXT: [[TMP1:%.*]] = ashr i64 [[X]], 63 -; CHECK-NEXT: [[R:%.*]] = trunc i64 [[TMP1]] to i32 -; CHECK-NEXT: ret i32 [[R]] +; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[TMP1]] to i32 +; CHECK-NEXT: ret i32 [[TMP2]] ; %t0 = lshr i64 %x, 63 call void @use64(i64 %t0) @@ -136,9 +136,9 @@ define i32 @n10(i64 %x) { ; CHECK-LABEL: @n10( -; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 -; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 -; CHECK-NEXT: [[R:%.*]] = xor i32 [[T1]], 1 +; CHECK-NEXT: [[TMP1:%.*]] = ashr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[TMP1]] to i32 +; CHECK-NEXT: [[R:%.*]] = add i32 [[TMP2]], 1 ; CHECK-NEXT: ret i32 [[R]] ; %t0 = lshr i64 %x, 63 diff --git a/llvm/test/Transforms/InstCombine/high-bit-signmask.ll b/llvm/test/Transforms/InstCombine/high-bit-signmask.ll --- a/llvm/test/Transforms/InstCombine/high-bit-signmask.ll +++ b/llvm/test/Transforms/InstCombine/high-bit-signmask.ll @@ -64,10 +64,10 @@ define i64 @t6(i64 %x) { ; CHECK-LABEL: @t6( -; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[TMP1:%.*]] = ashr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X]], 63 ; CHECK-NEXT: call void @use64(i64 [[T0]]) -; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X]], 63 -; CHECK-NEXT: ret i64 [[R]] +; CHECK-NEXT: ret i64 [[TMP1]] ; %t0 = lshr i64 %x, 63 call void @use64(i64 %t0) @@ -77,10 +77,10 @@ define i64 @n7(i64 %x) { ; CHECK-LABEL: @n7( -; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[TMP1:%.*]] = ashr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X]], 63 ; CHECK-NEXT: call void @use32(i64 [[T0]]) -; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X]], 63 -; CHECK-NEXT: ret i64 [[R]] +; CHECK-NEXT: ret i64 [[TMP1]] ; %t0 = lshr i64 %x, 63 call void @use32(i64 %t0) @@ -90,11 +90,11 @@ define i64 @n8(i64 %x) { ; CHECK-LABEL: @n8( -; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[TMP1:%.*]] = ashr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X]], 63 ; CHECK-NEXT: call void @use64(i64 [[T0]]) ; CHECK-NEXT: call void @use32(i64 [[T0]]) -; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X]], 63 -; CHECK-NEXT: ret i64 [[R]] +; CHECK-NEXT: ret i64 [[TMP1]] ; %t0 = lshr i64 %x, 63 call void @use64(i64 %t0) @@ -116,8 +116,8 @@ define i64 @n10(i64 %x) { ; CHECK-LABEL: @n10( -; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 -; CHECK-NEXT: [[R:%.*]] = xor i64 [[T0]], 1 +; CHECK-NEXT: [[TMP1:%.*]] = ashr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[R:%.*]] = add nsw i64 [[TMP1]], 1 ; CHECK-NEXT: ret i64 [[R]] ; %t0 = lshr i64 %x, 63 diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll --- a/llvm/test/Transforms/InstCombine/icmp.ll +++ b/llvm/test/Transforms/InstCombine/icmp.ll @@ -98,8 +98,8 @@ define i32 @test6(i32 %a, i32 %b) { ; CHECK-LABEL: @test6( -; CHECK-NEXT: [[A_LOBIT_NEG:%.*]] = ashr i32 [[A:%.*]], 31 -; CHECK-NEXT: [[F:%.*]] = and i32 [[A_LOBIT_NEG]], [[B:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[A:%.*]], 31 +; CHECK-NEXT: [[F:%.*]] = and i32 [[TMP1]], [[B:%.*]] ; CHECK-NEXT: ret i32 [[F]] ; %c = icmp sle i32 %a, -1 @@ -2905,10 +2905,10 @@ ; CHECK-LABEL: @f5( ; CHECK-NEXT: [[CONV:%.*]] = zext i8 [[A:%.*]] to i32 ; CHECK-NEXT: [[CONV3:%.*]] = zext i8 [[B:%.*]] to i32 +; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i32 [[CONV3]], [[CONV]] ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[CONV]], [[CONV3]] ; CHECK-NEXT: [[CMP4:%.*]] = icmp slt i32 [[SUB]], 0 -; CHECK-NEXT: [[SUB7:%.*]] = sub nsw i32 0, [[SUB]] -; CHECK-NEXT: [[SUB7_SUB:%.*]] = select i1 [[CMP4]], i32 [[SUB7]], i32 [[SUB]] +; CHECK-NEXT: [[SUB7_SUB:%.*]] = select i1 [[CMP4]], i32 [[TMP1]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[SUB7_SUB]] ; %conv = zext i8 %a to i32 @@ -3555,9 +3555,9 @@ define i32 @abs_preserve(i32 %x) { ; CHECK-LABEL: @abs_preserve( ; CHECK-NEXT: [[A:%.*]] = shl nsw i32 [[X:%.*]], 1 -; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[A]], 0 +; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[A]], -1 ; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[C]], i32 [[NEGA]], i32 [[A]] +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[C]], i32 [[A]], i32 [[NEGA]] ; CHECK-NEXT: ret i32 [[ABS]] ; %a = mul nsw i32 %x, 2 @@ -3597,7 +3597,7 @@ define <2 x i32> @Op1Negated_Vec(<2 x i32> %x) { ; CHECK-LABEL: @Op1Negated_Vec( ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]] -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]] ; CHECK-NEXT: ret <2 x i32> [[COND]] ; diff --git a/llvm/test/Transforms/InstCombine/max-of-nots.ll b/llvm/test/Transforms/InstCombine/max-of-nots.ll --- a/llvm/test/Transforms/InstCombine/max-of-nots.ll +++ b/llvm/test/Transforms/InstCombine/max-of-nots.ll @@ -242,9 +242,9 @@ ; CHECK-NEXT: [[YADD:%.*]] = add i32 [[Y:%.*]], 2 ; CHECK-NEXT: [[COND_I:%.*]] = icmp slt i32 [[YADD]], [[XORD]] ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[COND_I]], i32 [[YADD]], i32 [[XORD]] -; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[MIN]], 0 +; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[MIN]], -1 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[MIN]] -; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP2]], i32 [[SUB]], i32 [[MIN]] +; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP2]], i32 [[MIN]], i32 [[SUB]] ; CHECK-NEXT: ret i32 [[ABS]] ; diff --git a/llvm/test/Transforms/InstCombine/select_meta.ll b/llvm/test/Transforms/InstCombine/select_meta.ll --- a/llvm/test/Transforms/InstCombine/select_meta.ll +++ b/llvm/test/Transforms/InstCombine/select_meta.ll @@ -5,9 +5,9 @@ define i32 @foo(i32) local_unnamed_addr #0 { ; CHECK-LABEL: @foo( -; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 %0, 2 -; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[TMP2]], i32 20, i32 -20, !prof ![[$MD1:[0-9]+]] -; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[DOTV]], %0 +; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[TMP0:%.*]], 2 +; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[TMP2]], i32 20, i32 -20, !prof !0 +; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[DOTV]], [[TMP0]] ; CHECK-NEXT: ret i32 [[TMP3]] ; %2 = icmp sgt i32 %0, 2 @@ -19,8 +19,8 @@ define i8 @shrink_select(i1 %cond, i32 %x) { ; CHECK-LABEL: @shrink_select( -; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 %x to i8 -; CHECK-NEXT: [[TRUNC:%.*]] = select i1 %cond, i8 [[TMP1]], i8 42, !prof ![[$MD1]] +; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i8 +; CHECK-NEXT: [[TRUNC:%.*]] = select i1 [[COND:%.*]], i8 [[TMP1]], i8 42, !prof !0 ; CHECK-NEXT: ret i8 [[TRUNC]] ; %sel = select i1 %cond, i32 %x, i32 42, !prof !1 @@ -30,12 +30,12 @@ define void @min_max_bitcast(<4 x float> %a, <4 x float> %b, <4 x i32>* %ptr1, <4 x i32>* %ptr2) { ; CHECK-LABEL: @min_max_bitcast( -; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <4 x float> %a, %b -; CHECK-NEXT: [[SEL1_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> %a, <4 x float> %b, !prof ![[$MD1]] -; CHECK-NEXT: [[SEL2_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> %b, <4 x float> %a, !prof ![[$MD1]] -; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32>* %ptr1 to <4 x float>* +; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <4 x float> [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[SEL1_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> [[A]], <4 x float> [[B]], !prof !0 +; CHECK-NEXT: [[SEL2_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> [[B]], <4 x float> [[A]], !prof !0 +; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32>* [[PTR1:%.*]] to <4 x float>* ; CHECK-NEXT: store <4 x float> [[SEL1_V]], <4 x float>* [[TMP1]], align 16 -; CHECK-NEXT: [[TMP2:%.*]] = bitcast <4 x i32>* %ptr2 to <4 x float>* +; CHECK-NEXT: [[TMP2:%.*]] = bitcast <4 x i32>* [[PTR2:%.*]] to <4 x float>* ; CHECK-NEXT: store <4 x float> [[SEL2_V]], <4 x float>* [[TMP2]], align 16 ; CHECK-NEXT: ret void ; @@ -51,10 +51,10 @@ define i32 @foo2(i32, i32) local_unnamed_addr #0 { ; CHECK-LABEL: @foo2( -; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i32 %0, 2 -; CHECK-NEXT: [[TMP4:%.*]] = sub i32 0, %1 -; CHECK-NEXT: [[DOTP:%.*]] = select i1 [[TMP3]], i32 %1, i32 [[TMP4]], !prof ![[$MD1]] -; CHECK-NEXT: [[TMP5:%.*]] = add i32 [[DOTP]], %0 +; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i32 [[TMP0:%.*]], 2 +; CHECK-NEXT: [[TMP4:%.*]] = sub i32 0, [[TMP1:%.*]] +; CHECK-NEXT: [[DOTP:%.*]] = select i1 [[TMP3]], i32 [[TMP1]], i32 [[TMP4]], !prof !0 +; CHECK-NEXT: [[TMP5:%.*]] = add i32 [[DOTP]], [[TMP0]] ; CHECK-NEXT: ret i32 [[TMP5]] ; %3 = icmp sgt i32 %0, 2 @@ -66,9 +66,9 @@ define i64 @test43(i32 %a) nounwind { ; CHECK-LABEL: @test43( -; CHECK-NEXT: [[A_EXT:%.*]] = sext i32 %a to i64 +; CHECK-NEXT: [[A_EXT:%.*]] = sext i32 [[A:%.*]] to i64 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i64 [[A_EXT]], 0 -; CHECK-NEXT: [[MAX:%.*]] = select i1 [[TMP1]], i64 [[A_EXT]], i64 0, !prof ![[$MD1]] +; CHECK-NEXT: [[MAX:%.*]] = select i1 [[TMP1]], i64 [[A_EXT]], i64 0, !prof !0 ; CHECK-NEXT: ret i64 [[MAX]] ; %a_ext = sext i32 %a to i64 @@ -79,7 +79,7 @@ define <2 x i32> @scalar_select_of_vectors_sext(<2 x i1> %cca, i1 %ccb) { ; CHECK-LABEL: @scalar_select_of_vectors_sext( -; CHECK-NEXT: [[NARROW:%.*]] = select i1 %ccb, <2 x i1> %cca, <2 x i1> zeroinitializer, !prof ![[$MD1]] +; CHECK-NEXT: [[NARROW:%.*]] = select i1 [[CCB:%.*]], <2 x i1> [[CCA:%.*]], <2 x i1> zeroinitializer, !prof !0 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[NARROW]] to <2 x i32> ; CHECK-NEXT: ret <2 x i32> [[R]] ; @@ -91,8 +91,8 @@ define i16 @t7(i32 %a) { ; CHECK-LABEL: @t7( -; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 %a, -32768 -; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 %a, i32 -32768, !prof ![[$MD1]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[A:%.*]], -32768 +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[A]], i32 -32768, !prof !0 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP2]] to i16 ; CHECK-NEXT: ret i16 [[TMP3]] ; @@ -104,9 +104,9 @@ define i32 @abs_nabs_x01(i32 %x) { ; CHECK-LABEL: @abs_nabs_x01( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 %x, 0 -; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, %x -; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 %x, !prof ![[$MD3:[0-9]+]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1 +; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[X]] +; CHECK-NEXT: [[COND1:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[SUB]], !prof !0 ; CHECK-NEXT: ret i32 [[COND1]] ; %cmp = icmp sgt i32 %x, -1 @@ -122,9 +122,9 @@ define <2 x i32> @abs_nabs_x01_vec(<2 x i32> %x) { ; CHECK-LABEL: @abs_nabs_x01_vec( -; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> %x, zeroinitializer -; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, %x -; CHECK-NEXT: [[COND1:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> %x, !prof ![[$MD3]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X]] +; CHECK-NEXT: [[COND1:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[X]], <2 x i32> [[SUB]], !prof !0 ; CHECK-NEXT: ret <2 x i32> [[COND1]] ; %cmp = icmp sgt <2 x i32> %x, @@ -139,8 +139,8 @@ ; SMAX(SMAX(x, y), x) -> SMAX(x, y) define i32 @test30(i32 %x, i32 %y) { ; CHECK-LABEL: @test30( -; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 %x, %y -; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 %x, i32 %y, !prof ![[$MD1]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[Y]], !prof !0 ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp sgt i32 %x, %y @@ -153,8 +153,8 @@ ; SMAX(SMAX(75, X), 36) -> SMAX(X, 75) define i32 @test70(i32 %x) { ; CHECK-LABEL: @test70( -; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 %x, 75 -; CHECK-NEXT: [[COND:%.*]] = select i1 [[TMP1]], i32 %x, i32 75, !prof ![[$MD3]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], 75 +; CHECK-NEXT: [[COND:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 75, !prof !1 ; CHECK-NEXT: ret i32 [[COND]] ; %cmp = icmp slt i32 %x, 75 @@ -168,8 +168,8 @@ ; SMIN(SMIN(X, 92), 11) -> SMIN(X, 11) define i32 @test72(i32 %x) { ; CHECK-LABEL: @test72( -; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 %x, 11 -; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[TMP1]], i32 %x, i32 11, !prof ![[$MD4:[0-9]+]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], 11 +; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 11, !prof !2 ; CHECK-NEXT: ret i32 [[RETVAL]] ; %cmp = icmp sgt i32 %x, 92 @@ -183,8 +183,8 @@ ; SMAX(SMAX(X, 36), 75) -> SMAX(X, 75) define i32 @test74(i32 %x) { ; CHECK-LABEL: @test74( -; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 %x, 75 -; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[TMP1]], i32 %x, i32 75, !prof ![[$MD4]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], 75 +; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 75, !prof !2 ; CHECK-NEXT: ret i32 [[RETVAL]] ; %cmp = icmp slt i32 %x, 36 @@ -198,7 +198,7 @@ define i32 @smin1(i32 %x) { ; CHECK-LABEL: @smin1( ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], 0 -; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 0, !prof ![[$MD1]] +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 0, !prof !0 ; CHECK-NEXT: [[SEL:%.*]] = xor i32 [[TMP2]], -1 ; CHECK-NEXT: ret i32 [[SEL]] ; @@ -212,7 +212,7 @@ define i32 @smin2(i32 %x) { ; CHECK-LABEL: @smin2( ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], 0 -; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 0, !prof ![[$MD3]] +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 0, !prof !1 ; CHECK-NEXT: [[SEL:%.*]] = xor i32 [[TMP2]], -1 ; CHECK-NEXT: ret i32 [[SEL]] ; @@ -226,7 +226,7 @@ define i32 @smax1(i32 %x) { ; CHECK-LABEL: @smax1( ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], 0 -; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 0, !prof ![[$MD1]] +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 0, !prof !0 ; CHECK-NEXT: [[SEL:%.*]] = xor i32 [[TMP2]], -1 ; CHECK-NEXT: ret i32 [[SEL]] ; @@ -240,7 +240,7 @@ define i32 @smax2(i32 %x) { ; CHECK-LABEL: @smax2( ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], 0 -; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 0, !prof ![[$MD3]] +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 0, !prof !1 ; CHECK-NEXT: [[SEL:%.*]] = xor i32 [[TMP2]], -1 ; CHECK-NEXT: ret i32 [[SEL]] ; @@ -253,8 +253,8 @@ ; The compare should change, but the metadata remains the same because the select operands are not swapped. define i32 @umin1(i32 %x) { ; CHECK-LABEL: @umin1( -; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 %x, -2147483648 -; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 -2147483648, !prof ![[$MD1]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[X:%.*]], -2147483648 +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 -2147483648, !prof !0 ; CHECK-NEXT: ret i32 [[SEL]] ; %cmp = icmp sgt i32 %x, -1 @@ -265,8 +265,8 @@ ; The compare should change, and the metadata is swapped because the select operands are swapped. define i32 @umin2(i32 %x) { ; CHECK-LABEL: @umin2( -; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 %x, 2147483647 -; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 2147483647, !prof ![[$MD3]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[X:%.*]], 2147483647 +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 2147483647, !prof !1 ; CHECK-NEXT: ret i32 [[SEL]] ; %cmp = icmp slt i32 %x, 0 @@ -277,8 +277,8 @@ ; The compare should change, but the metadata remains the same because the select operands are not swapped. define i32 @umax1(i32 %x) { ; CHECK-LABEL: @umax1( -; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 %x, 2147483647 -; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 2147483647, !prof ![[$MD1]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[X:%.*]], 2147483647 +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 2147483647, !prof !0 ; CHECK-NEXT: ret i32 [[SEL]] ; %cmp = icmp slt i32 %x, 0 @@ -289,8 +289,8 @@ ; The compare should change, and the metadata is swapped because the select operands are swapped. define i32 @umax2(i32 %x) { ; CHECK-LABEL: @umax2( -; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 %x, -2147483648 -; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 -2147483648, !prof ![[$MD3]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[X:%.*]], -2147483648 +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 -2147483648, !prof !1 ; CHECK-NEXT: ret i32 [[SEL]] ; %cmp = icmp sgt i32 %x, -1 @@ -302,7 +302,7 @@ define i32 @not_cond(i1 %c, i32 %tv, i32 %fv) { ; CHECK-LABEL: @not_cond( -; CHECK-NEXT: [[R:%.*]] = select i1 [[C:%.*]], i32 [[FV:%.*]], i32 [[TV:%.*]], !prof ![[$MD3]] +; CHECK-NEXT: [[R:%.*]] = select i1 [[C:%.*]], i32 [[FV:%.*]], i32 [[TV:%.*]], !prof !1 ; CHECK-NEXT: ret i32 [[R]] ; %notc = xor i1 %c, true @@ -314,7 +314,7 @@ define <2 x i32> @not_cond_vec(<2 x i1> %c, <2 x i32> %tv, <2 x i32> %fv) { ; CHECK-LABEL: @not_cond_vec( -; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i32> [[FV:%.*]], <2 x i32> [[TV:%.*]], !prof ![[$MD3]] +; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i32> [[FV:%.*]], <2 x i32> [[TV:%.*]], !prof !1 ; CHECK-NEXT: ret <2 x i32> [[R]] ; %notc = xor <2 x i1> %c, @@ -327,7 +327,7 @@ define <2 x i32> @not_cond_vec_undef(<2 x i1> %c, <2 x i32> %tv, <2 x i32> %fv) { ; CHECK-LABEL: @not_cond_vec_undef( -; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i32> [[FV:%.*]], <2 x i32> [[TV:%.*]], !prof ![[$MD3]] +; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i32> [[FV:%.*]], <2 x i32> [[TV:%.*]], !prof !1 ; CHECK-NEXT: ret <2 x i32> [[R]] ; %notc = xor <2 x i1> %c, @@ -339,7 +339,7 @@ !1 = !{!"branch_weights", i32 2, i32 10} !2 = !{!"branch_weights", i32 3, i32 10} -; CHECK-DAG: ![[$MD1]] = !{!"branch_weights", i32 2, i32 10} -; CHECK-DAG: ![[$MD3]] = !{!"branch_weights", i32 10, i32 2} -; CHECK-DAG: ![[$MD4]] = !{!"branch_weights", i32 10, i32 3} +; CHECK-DAG: !0 = !{!"branch_weights", i32 2, i32 10} +; CHECK-DAG: !1 = !{!"branch_weights", i32 10, i32 2} +; CHECK-DAG: !2 = !{!"branch_weights", i32 10, i32 3} diff --git a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll --- a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll +++ b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll @@ -31,8 +31,8 @@ ; Shift-left can be negated if all uses can be updated define i8 @t2(i8 %x, i8 %y) { ; CHECK-LABEL: @t2( -; CHECK-NEXT: [[T0:%.*]] = shl i8 -42, [[Y:%.*]] -; CHECK-NEXT: [[T1:%.*]] = sub i8 [[X:%.*]], [[T0]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i8 42, [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = add i8 [[TMP1]], [[X:%.*]] ; CHECK-NEXT: ret i8 [[T1]] ; %t0 = shl i8 -42, %y @@ -55,8 +55,8 @@ ; CHECK-LABEL: @t3( ; CHECK-NEXT: [[T0:%.*]] = sub i8 0, [[Z:%.*]] ; CHECK-NEXT: call void @use8(i8 [[T0]]) -; CHECK-NEXT: [[T1:%.*]] = shl i8 [[T0]], [[Y:%.*]] -; CHECK-NEXT: [[T2:%.*]] = sub i8 [[X:%.*]], [[T1]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[Z]], [[Y:%.*]] +; CHECK-NEXT: [[T2:%.*]] = add i8 [[TMP1]], [[X:%.*]] ; CHECK-NEXT: ret i8 [[T2]] ; %t0 = sub i8 0, %z @@ -85,8 +85,8 @@ ; Select can be negated if all it's operands can be negated and all the users of select can be updated define i8 @t4(i8 %x, i1 %y) { ; CHECK-LABEL: @t4( -; CHECK-NEXT: [[T0:%.*]] = select i1 [[Y:%.*]], i8 -42, i8 44 -; CHECK-NEXT: [[T1:%.*]] = sub i8 [[X:%.*]], [[T0]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[Y:%.*]], i8 42, i8 -44 +; CHECK-NEXT: [[T1:%.*]] = add i8 [[TMP1]], [[X:%.*]] ; CHECK-NEXT: ret i8 [[T1]] ; %t0 = select i1 %y, i8 -42, i8 44 @@ -119,8 +119,8 @@ ; CHECK-LABEL: @t6( ; CHECK-NEXT: [[T0:%.*]] = sub i8 0, [[Z:%.*]] ; CHECK-NEXT: call void @use8(i8 [[T0]]) -; CHECK-NEXT: [[T1:%.*]] = select i1 [[Y:%.*]], i8 -42, i8 [[T0]] -; CHECK-NEXT: [[T2:%.*]] = sub i8 [[X:%.*]], [[T1]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[Y:%.*]], i8 42, i8 [[Z]] +; CHECK-NEXT: [[T2:%.*]] = add i8 [[TMP1]], [[X:%.*]] ; CHECK-NEXT: ret i8 [[T2]] ; %t0 = sub i8 0, %z @@ -131,9 +131,9 @@ } define i8 @t7(i8 %x, i1 %y, i8 %z) { ; CHECK-LABEL: @t7( -; CHECK-NEXT: [[T0:%.*]] = shl i8 1, [[Z:%.*]] -; CHECK-NEXT: [[T1:%.*]] = select i1 [[Y:%.*]], i8 0, i8 [[T0]] -; CHECK-NEXT: [[T2:%.*]] = sub i8 [[X:%.*]], [[T1]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -1, [[Z:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[Y:%.*]], i8 0, i8 [[TMP1]] +; CHECK-NEXT: [[T2:%.*]] = add i8 [[TMP2]], [[X:%.*]] ; CHECK-NEXT: ret i8 [[T2]] ; %t0 = shl i8 1, %z @@ -160,8 +160,8 @@ ; x - (y - z) -> x - y + z -> x + (z - y) define i8 @t9(i8 %x, i8 %y) { ; CHECK-LABEL: @t9( -; CHECK-NEXT: [[T0_NEG:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: ret i8 [[T0_NEG]] +; CHECK-NEXT: [[TMP1:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret i8 [[TMP1]] ; %t0 = sub i8 %y, %x %t1 = sub i8 0, %t0 @@ -169,10 +169,10 @@ } define i8 @n10(i8 %x, i8 %y, i8 %z) { ; CHECK-LABEL: @n10( -; CHECK-NEXT: [[T0:%.*]] = sub i8 [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T0:%.*]] = sub i8 [[Y]], [[X]] ; CHECK-NEXT: call void @use8(i8 [[T0]]) -; CHECK-NEXT: [[T1:%.*]] = sub i8 0, [[T0]] -; CHECK-NEXT: ret i8 [[T1]] +; CHECK-NEXT: ret i8 [[TMP1]] ; %t0 = sub i8 %y, %x call void @use8(i8 %t0) @@ -204,8 +204,8 @@ ; CHECK-LABEL: @n13( ; CHECK-NEXT: [[T0:%.*]] = sub i8 0, [[Y:%.*]] ; CHECK-NEXT: call void @use8(i8 [[T0]]) -; CHECK-NEXT: [[T11:%.*]] = sub i8 [[Y]], [[Z:%.*]] -; CHECK-NEXT: [[T2:%.*]] = add i8 [[T11]], [[X:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = sub i8 [[Y]], [[Z:%.*]] +; CHECK-NEXT: [[T2:%.*]] = add i8 [[TMP1]], [[X:%.*]] ; CHECK-NEXT: ret i8 [[T2]] ; %t0 = sub i8 0, %y @@ -242,7 +242,7 @@ ; CHECK-LABEL: @t15( ; CHECK-NEXT: [[T0:%.*]] = sub i8 0, [[Y:%.*]] ; CHECK-NEXT: call void @use8(i8 [[T0]]) -; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[Z:%.*]], [[Y]] +; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[Y]], [[Z:%.*]] ; CHECK-NEXT: [[T2:%.*]] = add i8 [[TMP1]], [[X:%.*]] ; CHECK-NEXT: ret i8 [[T2]] ; @@ -279,8 +279,8 @@ ; CHECK: else: ; CHECK-NEXT: br label [[END]] ; CHECK: end: -; CHECK-NEXT: [[Z:%.*]] = phi i8 [ [[X:%.*]], [[THEN]] ], [ 42, [[ELSE]] ] -; CHECK-NEXT: ret i8 [[Z]] +; CHECK-NEXT: [[TMP0:%.*]] = phi i8 [ [[X:%.*]], [[THEN]] ], [ 42, [[ELSE]] ] +; CHECK-NEXT: ret i8 [[TMP0]] ; begin: br i1 %c, label %then, label %else @@ -352,9 +352,9 @@ ; truncation can be negated if it's operand can be negated define i8 @t20(i8 %x, i16 %y) { ; CHECK-LABEL: @t20( -; CHECK-NEXT: [[T0:%.*]] = shl i16 -42, [[Y:%.*]] -; CHECK-NEXT: [[T1:%.*]] = trunc i16 [[T0]] to i8 -; CHECK-NEXT: [[T2:%.*]] = sub i8 [[X:%.*]], [[T1]] +; CHECK-NEXT: [[TMP1:%.*]] = shl i16 42, [[Y:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = trunc i16 [[TMP1]] to i8 +; CHECK-NEXT: [[T2:%.*]] = add i8 [[TMP2]], [[X:%.*]] ; CHECK-NEXT: ret i8 [[T2]] ; %t0 = shl i16 -42, %y @@ -380,8 +380,8 @@ define i4 @negate_xor(i4 %x) { ; CHECK-LABEL: @negate_xor( ; CHECK-NEXT: [[TMP1:%.*]] = xor i4 [[X:%.*]], -6 -; CHECK-NEXT: [[O_NEG:%.*]] = add i4 [[TMP1]], 1 -; CHECK-NEXT: ret i4 [[O_NEG]] +; CHECK-NEXT: [[TMP2:%.*]] = add i4 [[TMP1]], 1 +; CHECK-NEXT: ret i4 [[TMP2]] ; %o = xor i4 %x, 5 %r = sub i4 0, %o @@ -391,8 +391,8 @@ define <2 x i4> @negate_xor_vec(<2 x i4> %x) { ; CHECK-LABEL: @negate_xor_vec( ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i4> [[X:%.*]], -; CHECK-NEXT: [[O_NEG:%.*]] = add <2 x i4> [[TMP1]], -; CHECK-NEXT: ret <2 x i4> [[O_NEG]] +; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i4> [[TMP1]], +; CHECK-NEXT: ret <2 x i4> [[TMP2]] ; %o = xor <2 x i4> %x, %r = sub <2 x i4> zeroinitializer, %o @@ -415,9 +415,9 @@ define i4 @negate_shl_xor(i4 %x, i4 %y) { ; CHECK-LABEL: @negate_shl_xor( ; CHECK-NEXT: [[TMP1:%.*]] = xor i4 [[X:%.*]], -6 -; CHECK-NEXT: [[O_NEG:%.*]] = add i4 [[TMP1]], 1 -; CHECK-NEXT: [[S_NEG:%.*]] = shl i4 [[O_NEG]], [[Y:%.*]] -; CHECK-NEXT: ret i4 [[S_NEG]] +; CHECK-NEXT: [[TMP2:%.*]] = add i4 [[TMP1]], 1 +; CHECK-NEXT: [[TMP3:%.*]] = shl i4 [[TMP2]], [[Y:%.*]] +; CHECK-NEXT: ret i4 [[TMP3]] ; %o = xor i4 %x, 5 %s = shl i4 %o, %y @@ -427,11 +427,11 @@ define i8 @negate_shl_not_uses(i8 %x, i8 %y) { ; CHECK-LABEL: @negate_shl_not_uses( -; CHECK-NEXT: [[O:%.*]] = xor i8 [[X:%.*]], -1 +; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X:%.*]], 1 +; CHECK-NEXT: [[O:%.*]] = xor i8 [[X]], -1 ; CHECK-NEXT: call void @use8(i8 [[O]]) -; CHECK-NEXT: [[O_NEG:%.*]] = add i8 [[X]], 1 -; CHECK-NEXT: [[S_NEG:%.*]] = shl i8 [[O_NEG]], [[Y:%.*]] -; CHECK-NEXT: ret i8 [[S_NEG]] +; CHECK-NEXT: [[TMP2:%.*]] = shl i8 [[TMP1]], [[Y:%.*]] +; CHECK-NEXT: ret i8 [[TMP2]] ; %o = xor i8 %x, -1 call void @use8(i8 %o) @@ -442,11 +442,11 @@ define <2 x i4> @negate_mul_not_uses_vec(<2 x i4> %x, <2 x i4> %y) { ; CHECK-LABEL: @negate_mul_not_uses_vec( -; CHECK-NEXT: [[O:%.*]] = xor <2 x i4> [[X:%.*]], +; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i4> [[X:%.*]], +; CHECK-NEXT: [[O:%.*]] = xor <2 x i4> [[X]], ; CHECK-NEXT: call void @use_v2i4(<2 x i4> [[O]]) -; CHECK-NEXT: [[O_NEG:%.*]] = add <2 x i4> [[X]], -; CHECK-NEXT: [[S_NEG:%.*]] = mul <2 x i4> [[O_NEG]], [[Y:%.*]] -; CHECK-NEXT: ret <2 x i4> [[S_NEG]] +; CHECK-NEXT: [[TMP2:%.*]] = mul <2 x i4> [[TMP1]], [[Y:%.*]] +; CHECK-NEXT: ret <2 x i4> [[TMP2]] ; %o = xor <2 x i4> %x, call void @use_v2i4(<2 x i4> %o) diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll --- a/llvm/test/Transforms/InstCombine/sub.ll +++ b/llvm/test/Transforms/InstCombine/sub.ll @@ -555,11 +555,11 @@ define i64 @test_neg_shl_sub_extra_use1(i64 %a, i64 %b, i64* %p) { ; CHECK-LABEL: @test_neg_shl_sub_extra_use1( -; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = sub i64 [[B:%.*]], [[A:%.*]] +; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[A]], [[B]] ; CHECK-NEXT: store i64 [[SUB]], i64* [[P:%.*]], align 8 -; CHECK-NEXT: [[MUL:%.*]] = shl i64 [[SUB]], 2 -; CHECK-NEXT: [[NEG:%.*]] = sub i64 0, [[MUL]] -; CHECK-NEXT: ret i64 [[NEG]] +; CHECK-NEXT: [[TMP2:%.*]] = shl i64 [[TMP1]], 2 +; CHECK-NEXT: ret i64 [[TMP2]] ; %sub = sub i64 %a, %b store i64 %sub, i64* %p @@ -621,10 +621,10 @@ define i64 @test_neg_zext_i1_extra_use(i1 %a, i64 %b, i64* %p) { ; CHECK-LABEL: @test_neg_zext_i1_extra_use( -; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[A:%.*]] to i64 -; CHECK-NEXT: [[EXT_NEG:%.*]] = sext i1 [[A]] to i64 +; CHECK-NEXT: [[TMP1:%.*]] = sext i1 [[A:%.*]] to i64 +; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[A]] to i64 ; CHECK-NEXT: store i64 [[EXT]], i64* [[P:%.*]], align 8 -; CHECK-NEXT: ret i64 [[EXT_NEG]] +; CHECK-NEXT: ret i64 [[TMP1]] ; %ext = zext i1 %a to i64 %neg = sub i64 0, %ext @@ -634,10 +634,10 @@ define i64 @test_neg_sext_i1_extra_use(i1 %a, i64 %b, i64* %p) { ; CHECK-LABEL: @test_neg_sext_i1_extra_use( -; CHECK-NEXT: [[EXT:%.*]] = sext i1 [[A:%.*]] to i64 -; CHECK-NEXT: [[EXT_NEG:%.*]] = zext i1 [[A]] to i64 +; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[A:%.*]] to i64 +; CHECK-NEXT: [[EXT:%.*]] = sext i1 [[A]] to i64 ; CHECK-NEXT: store i64 [[EXT]], i64* [[P:%.*]], align 8 -; CHECK-NEXT: ret i64 [[EXT_NEG]] +; CHECK-NEXT: ret i64 [[TMP1]] ; %ext = sext i1 %a to i64 %neg = sub i64 0, %ext @@ -702,9 +702,9 @@ define i64 @test_neg_mul_sub_commuted(i64 %a, i64 %b, i64 %c) { ; CHECK-LABEL: @test_neg_mul_sub_commuted( ; CHECK-NEXT: [[COMPLEX:%.*]] = mul i64 [[C:%.*]], [[C]] -; CHECK-NEXT: [[SUB_NEG:%.*]] = sub i64 [[B:%.*]], [[A:%.*]] -; CHECK-NEXT: [[MUL_NEG:%.*]] = mul i64 [[COMPLEX]], [[SUB_NEG]] -; CHECK-NEXT: ret i64 [[MUL_NEG]] +; CHECK-NEXT: [[TMP1:%.*]] = sub i64 [[B:%.*]], [[A:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = mul i64 [[TMP1]], [[COMPLEX]] +; CHECK-NEXT: ret i64 [[TMP2]] ; %complex = mul i64 %c, %c %sub = sub i64 %a, %b diff --git a/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll b/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll --- a/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll +++ b/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll @@ -105,10 +105,10 @@ define i64 @zext_negate_extra_use(i1 %A) { ; CHECK-LABEL: @zext_negate_extra_use( -; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[A:%.*]] to i64 -; CHECK-NEXT: [[SUB:%.*]] = sext i1 [[A]] to i64 +; CHECK-NEXT: [[TMP1:%.*]] = sext i1 [[A:%.*]] to i64 +; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[A]] to i64 ; CHECK-NEXT: call void @use(i64 [[EXT]]) -; CHECK-NEXT: ret i64 [[SUB]] +; CHECK-NEXT: ret i64 [[TMP1]] ; %ext = zext i1 %A to i64 %sub = sub i64 0, %ext @@ -191,10 +191,10 @@ define i64 @sext_negate_extra_use(i1 %A) { ; CHECK-LABEL: @sext_negate_extra_use( -; CHECK-NEXT: [[EXT:%.*]] = sext i1 [[A:%.*]] to i64 -; CHECK-NEXT: [[SUB:%.*]] = zext i1 [[A]] to i64 +; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[A:%.*]] to i64 +; CHECK-NEXT: [[EXT:%.*]] = sext i1 [[A]] to i64 ; CHECK-NEXT: call void @use(i64 [[EXT]]) -; CHECK-NEXT: ret i64 [[SUB]] +; CHECK-NEXT: ret i64 [[TMP1]] ; %ext = sext i1 %A to i64 %sub = sub i64 0, %ext @@ -294,7 +294,7 @@ define <2 x i8> @sext_sub_vec_nsw(<2 x i8> %x, <2 x i1> %y) { ; CHECK-LABEL: @sext_sub_vec_nsw( ; CHECK-NEXT: [[TMP1:%.*]] = zext <2 x i1> [[Y:%.*]] to <2 x i8> -; CHECK-NEXT: [[SUB:%.*]] = add nsw <2 x i8> [[TMP1]], [[X:%.*]] +; CHECK-NEXT: [[SUB:%.*]] = add <2 x i8> [[TMP1]], [[X:%.*]] ; CHECK-NEXT: ret <2 x i8> [[SUB]] ; %sext = sext <2 x i1> %y to <2 x i8> diff --git a/llvm/test/Transforms/PhaseOrdering/min-max-abs-cse.ll b/llvm/test/Transforms/PhaseOrdering/min-max-abs-cse.ll --- a/llvm/test/Transforms/PhaseOrdering/min-max-abs-cse.ll +++ b/llvm/test/Transforms/PhaseOrdering/min-max-abs-cse.ll @@ -34,9 +34,12 @@ define i8 @abs_swapped(i8 %a) { ; CHECK-LABEL: @abs_swapped( ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]] -; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A]], 0 -; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[NEG]], i8 [[A]] -; CHECK-NEXT: ret i8 [[M1]] +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A]], 0 +; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i8 [[A]], 0 +; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]] +; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 [[A]] +; CHECK-NEXT: [[R:%.*]] = or i8 [[M2]], [[M1]] +; CHECK-NEXT: ret i8 [[R]] ; %neg = sub i8 0, %a %cmp1 = icmp sgt i8 %a, 0 @@ -51,7 +54,13 @@ define i8 @nabs_swapped(i8 %a) { ; CHECK-LABEL: @nabs_swapped( -; CHECK-NEXT: ret i8 0 +; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]] +; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A]], 0 +; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[A]], 0 +; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]] +; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 [[A]] +; CHECK-NEXT: [[R:%.*]] = xor i8 [[M2]], [[M1]] +; CHECK-NEXT: ret i8 [[R]] ; %neg = sub i8 0, %a %cmp1 = icmp slt i8 %a, 0 @@ -66,7 +75,13 @@ define i8 @abs_different_constants(i8 %a) { ; CHECK-LABEL: @abs_different_constants( -; CHECK-NEXT: ret i8 0 +; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]] +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A]], -1 +; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i8 [[A]], 0 +; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]] +; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 [[A]] +; CHECK-NEXT: [[R:%.*]] = xor i8 [[M2]], [[M1]] +; CHECK-NEXT: ret i8 [[R]] ; %neg = sub i8 0, %a %cmp1 = icmp sgt i8 %a, -1 @@ -83,8 +98,11 @@ ; CHECK-LABEL: @nabs_different_constants( ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]] ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A]], 0 +; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[A]], -1 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]] -; CHECK-NEXT: ret i8 [[M1]] +; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 [[A]] +; CHECK-NEXT: [[R:%.*]] = or i8 [[M2]], [[M1]] +; CHECK-NEXT: ret i8 [[R]] ; %neg = sub i8 0, %a %cmp1 = icmp slt i8 %a, 0