[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / llvm / tools / llvm-reduce / deltas / ReduceInstructionFlags.cpp
blobc73e74e4c25c941e7093119c4712ee285f61ea42
1 //===- ReduceInstructionFlags.cpp - Specialized Delta Pass ----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Try to remove optimization flags on instructions
11 //===----------------------------------------------------------------------===//
13 #include "ReduceInstructionFlags.h"
14 #include "Delta.h"
15 #include "llvm/IR/InstIterator.h"
16 #include "llvm/IR/Instruction.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/IR/Operator.h"
20 using namespace llvm;
22 static void reduceFlagsInModule(Oracle &O, ReducerWorkItem &WorkItem) {
23 for (Function &F : WorkItem.getModule()) {
24 for (Instruction &I : instructions(F)) {
25 if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(&I)) {
26 if (OBO->hasNoSignedWrap() && !O.shouldKeep())
27 I.setHasNoSignedWrap(false);
28 if (OBO->hasNoUnsignedWrap() && !O.shouldKeep())
29 I.setHasNoUnsignedWrap(false);
30 } else if (auto *PE = dyn_cast<PossiblyExactOperator>(&I)) {
31 if (PE->isExact() && !O.shouldKeep())
32 I.setIsExact(false);
33 } else if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
34 if (GEP->isInBounds() && !O.shouldKeep())
35 GEP->setIsInBounds(false);
36 } else if (auto *FPOp = dyn_cast<FPMathOperator>(&I)) {
37 FastMathFlags Flags = FPOp->getFastMathFlags();
39 if (Flags.allowReassoc() && !O.shouldKeep())
40 Flags.setAllowReassoc(false);
42 if (Flags.noNaNs() && !O.shouldKeep())
43 Flags.setNoNaNs(false);
45 if (Flags.noInfs() && !O.shouldKeep())
46 Flags.setNoInfs(false);
48 if (Flags.noSignedZeros() && !O.shouldKeep())
49 Flags.setNoSignedZeros(false);
51 if (Flags.allowReciprocal() && !O.shouldKeep())
52 Flags.setAllowReciprocal(false);
54 if (Flags.allowContract() && !O.shouldKeep())
55 Flags.setAllowContract(false);
57 if (Flags.approxFunc() && !O.shouldKeep())
58 Flags.setApproxFunc(false);
60 I.copyFastMathFlags(Flags);
66 void llvm::reduceInstructionFlagsDeltaPass(TestRunner &Test) {
67 runDeltaPass(Test, reduceFlagsInModule, "Reducing Instruction Flags");