Debian Codegraph @

llvm-project/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp

raw
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
10 //
11 //===----------------------------------------------------------------------===//
12
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"
19
20 using namespace llvm;
21
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();
38
39 if (Flags.allowReassoc() && !O.shouldKeep())
40 Flags.setAllowReassoc(false);
41
42 if (Flags.noNaNs() && !O.shouldKeep())
43 Flags.setNoNaNs(false);
44
45 if (Flags.noInfs() && !O.shouldKeep())
46 Flags.setNoInfs(false);
47
48 if (Flags.noSignedZeros() && !O.shouldKeep())
49 Flags.setNoSignedZeros(false);
50
51 if (Flags.allowReciprocal() && !O.shouldKeep())
52 Flags.setAllowReciprocal(false);
53
54 if (Flags.allowContract() && !O.shouldKeep())
55 Flags.setAllowContract(false);
56
57 if (Flags.approxFunc() && !O.shouldKeep())
58 Flags.setApproxFunc(false);
59
60 I.copyFastMathFlags(Flags);
61 }
62 }
63 }
64 }
65
66 void llvm::reduceInstructionFlagsDeltaPass(TestRunner &Test) {
67 runDeltaPass(Test, reduceFlagsInModule, "Reducing Instruction Flags");
68 }