[FuzzMutate] InstModStrategy: switch nsw/nuw/inbount instead of repeated setting it
authorPeter Rong <PeterRong96@gmail.com>
Mon, 12 Dec 2022 23:35:54 +0000 (15:35 -0800)
committerPeter Rong <PeterRong96@gmail.com>
Wed, 14 Dec 2022 04:50:00 +0000 (20:50 -0800)
Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D139890

llvm/lib/FuzzMutate/IRMutator.cpp

index 6c0c2dd..a588bc8 100644 (file)
@@ -224,10 +224,10 @@ void InstModificationIRStrategy::mutate(Instruction &Inst,
   case Instruction::Mul:
   case Instruction::Sub:
   case Instruction::Shl:
-    Modifications.push_back([&Inst]() { Inst.setHasNoSignedWrap(true); });
-    Modifications.push_back([&Inst]() { Inst.setHasNoSignedWrap(false); });
-    Modifications.push_back([&Inst]() { Inst.setHasNoUnsignedWrap(true); });
-    Modifications.push_back([&Inst]() { Inst.setHasNoUnsignedWrap(false); });
+    Modifications.push_back(
+        [&Inst]() { Inst.setHasNoSignedWrap(!Inst.hasNoSignedWrap()); });
+    Modifications.push_back(
+        [&Inst]() { Inst.setHasNoUnsignedWrap(!Inst.hasNoUnsignedWrap()); });
     break;
   case Instruction::ICmp:
     CI = cast<ICmpInst>(&Inst);
@@ -240,8 +240,8 @@ void InstModificationIRStrategy::mutate(Instruction &Inst,
   // Add inbound flag.
   case Instruction::GetElementPtr:
     GEP = cast<GetElementPtrInst>(&Inst);
-    Modifications.push_back([GEP]() { GEP->setIsInBounds(true); });
-    Modifications.push_back([GEP]() { GEP->setIsInBounds(false); });
+    Modifications.push_back(
+        [GEP]() { GEP->setIsInBounds(!GEP->isInBounds()); });
     break;
   // Add exact flag.
   case Instruction::UDiv: