Simplify expressions involving boolean constants with clang-tidy
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 9 Mar 2015 01:57:13 +0000 (01:57 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 9 Mar 2015 01:57:13 +0000 (01:57 +0000)
Patch by Richard (legalize at xmission dot com).

Differential Revision: http://reviews.llvm.org/D8154

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231617 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
lib/Analysis/ScalarEvolution.cpp
lib/Bitcode/Reader/BitstreamReader.cpp
lib/CodeGen/CodeGenPrepare.cpp
lib/CodeGen/IfConversion.cpp
lib/CodeGen/PeepholeOptimizer.cpp
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
lib/IR/DiagnosticInfo.cpp
lib/IR/InlineAsm.cpp
lib/IR/Verifier.cpp
lib/MC/MCParser/AsmParser.cpp
lib/MC/MCParser/DarwinAsmParser.cpp
lib/Support/APFloat.cpp
lib/Support/CommandLine.cpp
lib/Target/NVPTX/NVPTXLowerAggrCopies.cpp
lib/Transforms/InstCombine/InstCombineSelect.cpp

index 19e3633fcc5cc9fde107506af0a6a283e6b4f520..49adbc376765795af7af5666d4eb86025921eb72 100644 (file)
@@ -6198,7 +6198,7 @@ ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L, bool ControlsExit) {
           dyn_cast<ConstantInt>(ConstantExpr::getICmp(CmpInst::ICMP_ULT,
                                                       R1->getValue(),
                                                       R2->getValue()))) {
-        if (CB->getZExtValue() == false)
+        if (!CB->getZExtValue())
           std::swap(R1, R2);   // R1 is the minimum root now.
 
         // We can only use this value if the chrec ends up with an exact zero
@@ -7521,7 +7521,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
       if (ConstantInt *CB =
           dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT,
                          R1->getValue(), R2->getValue()))) {
-        if (CB->getZExtValue() == false)
+        if (!CB->getZExtValue())
           std::swap(R1, R2);   // R1 is the minimum root now.
 
         // Make sure the root is not off by one.  The returned iteration should
index ca68257c7311b0a5f5ceaf07e8ae524287eb399c..beaaf7a7d6673d27c681161ba5c38c63167e9e60 100644 (file)
@@ -245,7 +245,7 @@ void BitstreamCursor::ReadAbbrevRecord() {
   BitCodeAbbrev *Abbv = new BitCodeAbbrev();
   unsigned NumOpInfo = ReadVBR(5);
   for (unsigned i = 0; i != NumOpInfo; ++i) {
-    bool IsLiteral = Read(1) ? true : false;
+    bool IsLiteral = Read(1);
     if (IsLiteral) {
       Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8)));
       continue;
index 81a149a99e3696c9e02f4e392b7a871714d7ad53..bcdfec77cba2d2bb5a02f755ce3e92a1b56e08b5 100644 (file)
@@ -4466,8 +4466,7 @@ static void scaleWeights(uint64_t &NewTrue, uint64_t &NewFalse) {
 /// FIXME: Remove the (equivalent?) implementation in SelectionDAG.
 ///
 bool CodeGenPrepare::splitBranchCondition(Function &F) {
-  if (!TM || TM->Options.EnableFastISel != true ||
-      !TLI || TLI->isJumpExpensive())
+  if (!TM || !TM->Options.EnableFastISel || !TLI || TLI->isJumpExpensive())
     return false;
 
   bool MadeChange = false;
index 1a1f2a9d03cbdfcca46e2dcbe40df14523122f2f..2395f32061d911c205e01dc6169cb2ac968d435d 100644 (file)
@@ -247,7 +247,7 @@ namespace {
         return true;
       else if (Incr1 == Incr2) {
         // Favors subsumption.
-        if (C1->NeedSubsumption == false && C2->NeedSubsumption == true)
+        if (!C1->NeedSubsumption && C2->NeedSubsumption)
           return true;
         else if (C1->NeedSubsumption == C2->NeedSubsumption) {
           // Favors diamond over triangle, etc.
index 2800d846ff3929f0c1d3f081e643f7ff3f05c93a..bc39e556cf0522b82ee4a1f6f01a545e549172f5 100644 (file)
@@ -915,7 +915,7 @@ bool PeepholeOptimizer::optimizeCoalescableCopy(MachineInstr *MI) {
   // => v0 = COPY v1
   // Currently we haven't seen motivating example for that and we
   // want to avoid untested code.
-  NumRewrittenCopies += Changed == true;
+  NumRewrittenCopies += Changed;
   return Changed;
 }
 
index 0f3ca0f2f3921551bbe4a019c313e4623cafca36..6278170cd88aec9c1085e0909983149a2b19b4f6 100644 (file)
@@ -1128,7 +1128,7 @@ relocation_iterator RuntimeDyldELF::processRelocationRef(
           RangeOverflow = true;
         }
       }
-      if (SymType == SymbolRef::ST_Unknown || RangeOverflow == true) {
+      if (SymType == SymbolRef::ST_Unknown || RangeOverflow) {
         // It is an external symbol (SymbolRef::ST_Unknown) or within a range
         // larger than 24-bits.
         StubMap::const_iterator i = Stubs.find(Value);
index cfb699a31717c6a19690e7eb0b84ba162e64f0dc..5608589a56ecf3af9b8e036e42ce3daf82379e5b 100644 (file)
@@ -129,7 +129,7 @@ void DiagnosticInfoSampleProfile::print(DiagnosticPrinter &DP) const {
 }
 
 bool DiagnosticInfoOptimizationBase::isLocationAvailable() const {
-  return getDebugLoc().isUnknown() == false;
+  return !getDebugLoc().isUnknown();
 }
 
 void DiagnosticInfoOptimizationBase::getLocation(StringRef *Filename,
index 5b73561c5039370871990a450550d4da14073197..b456d9f5869671043c1fa9b3b8c602183be4fc99 100644 (file)
@@ -75,7 +75,7 @@ bool InlineAsm::ConstraintInfo::Parse(StringRef Str,
   ConstraintCodeVector *pCodes = &Codes;
 
   // Initialize
-  isMultipleAlternative = (multipleAlternativeCount > 1 ? true : false);
+  isMultipleAlternative = multipleAlternativeCount > 1;
   if (isMultipleAlternative) {
     multipleAlternatives.resize(multipleAlternativeCount);
     pCodes = &multipleAlternatives[0].Codes;
index 1b66fa0b1b8e930e1f25abd1919b255ffeb992a8..06104d54cbacb9d1a0d09ab61bcc9f3c25e4a3df 100644 (file)
@@ -2709,7 +2709,7 @@ Verifier::VerifyIntrinsicIsVarArg(bool isVarArg,
 
   // If there are no descriptors left, then it can't be a vararg.
   if (Infos.empty())
-    return isVarArg ? true : false;
+    return isVarArg;
 
   // There should be only one descriptor remaining at this point.
   if (Infos.size() != 1)
@@ -2719,7 +2719,7 @@ Verifier::VerifyIntrinsicIsVarArg(bool isVarArg,
   IITDescriptor D = Infos.front();
   Infos = Infos.slice(1);
   if (D.Kind == IITDescriptor::VarArg)
-    return isVarArg ? false : true;
+    return !isVarArg;
 
   return true;
 }
index ef6a54002d35e92e452f2aebef90a24472b5ca53..a06f15b8d61caec1ff562160f18a804c7ee62a5f 100644 (file)
@@ -2791,7 +2791,7 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
   if (FileNumber == -1)
     getStreamer().EmitFileDirective(Filename);
   else {
-    if (getContext().getGenDwarfForAssembly() == true)
+    if (getContext().getGenDwarfForAssembly())
       Error(DirectiveLoc,
             "input can't have .file dwarf directives when -g is "
             "used to generate dwarf debug info for assembly code");
index 3ea745eba57c051785dfdff4b0761a5a72aa29fa..9102dc397567b17f94bdd4c71fa40d8049e541c3 100644 (file)
@@ -626,7 +626,7 @@ bool DarwinAsmParser::parseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
   if (getLexer().isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.secure_log_unique' directive");
 
-  if (getContext().getSecureLogUsed() != false)
+  if (getContext().getSecureLogUsed())
     return Error(IDLoc, ".secure_log_unique specified multiple times");
 
   // Get the secure log path.
index 393ecf4784cb4a7fe299696d50b6e64c890c9f1a..535e80d7639d40042ad5f2fd98671c33b9456b4a 100644 (file)
@@ -1248,10 +1248,10 @@ APFloat::roundAwayFromZero(roundingMode rounding_mode,
     return false;
 
   case rmTowardPositive:
-    return sign == false;
+    return !sign;
 
   case rmTowardNegative:
-    return sign == true;
+    return sign;
   }
   llvm_unreachable("Invalid rounding mode found");
 }
index b49ec3684747eab00e55c306f9fe6467da32791d..f761aa6fc1c50c29946896d7df4a8ccd5b13e22a 100644 (file)
@@ -1516,7 +1516,7 @@ public:
 
   // Invoke the printer.
   void operator=(bool Value) {
-    if (Value == false)
+    if (!Value)
       return;
 
     StrOptionPairVector Opts;
@@ -1716,7 +1716,7 @@ static cl::opt<bool> PrintAllOptions(
     cl::init(false), cl::cat(GenericCategory));
 
 void HelpPrinterWrapper::operator=(bool Value) {
-  if (Value == false)
+  if (!Value)
     return;
 
   // Decide which printer to invoke. If more than one option category is
index f6b62b762cfb71bfebca55f62927db21db09cfab..52060d2783b1d284e88fe3ff17542b607f425d06 100644 (file)
@@ -120,7 +120,7 @@ bool NVPTXLowerAggrCopies::runOnFunction(Function &F) {
          ++II) {
       if (LoadInst *load = dyn_cast<LoadInst>(II)) {
 
-        if (load->hasOneUse() == false)
+        if (!load->hasOneUse())
           continue;
 
         if (DL.getTypeStoreSize(load->getType()) < MaxAggrCopySize)
index eff575ebcaab354f71900c1a3a10938aeaa7d6ac..02f1e75f1b81c718119cce94bd890d3a9bba2830 100644 (file)
@@ -927,7 +927,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
       return BinaryOperator::CreateAnd(NotCond, FalseVal);
     }
     if (ConstantInt *C = dyn_cast<ConstantInt>(FalseVal)) {
-      if (C->getZExtValue() == false) {
+      if (!C->getZExtValue()) {
         // Change: A = select B, C, false --> A = and B, C
         return BinaryOperator::CreateAnd(CondVal, TrueVal);
       }