Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / tools / llvm-reduce / deltas / SimplifyInstructions.cpp
blobfc21593c5415c0ed2bc80004d7edfa21c1067c10
1 //===- SimplifyInstructions.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 // This file implements a function which calls the Generic Delta pass in order
10 // to simplify Instructions in defined functions.
12 //===----------------------------------------------------------------------===//
14 #include "SimplifyInstructions.h"
15 #include "llvm/Analysis/InstructionSimplify.h"
16 #include "llvm/IR/Constants.h"
18 using namespace llvm;
20 /// Calls simplifyInstruction in each instruction in functions, and replaces
21 /// their values.
22 static void extractInstrFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
23 std::vector<Instruction *> InstsToDelete;
25 Module &Program = WorkItem.getModule();
26 const DataLayout &DL = Program.getDataLayout();
28 std::vector<Instruction *> InstToDelete;
29 for (auto &F : Program) {
30 for (auto &BB : F) {
31 for (auto &Inst : BB) {
33 SimplifyQuery Q(DL, &Inst);
34 if (Value *Simplified = simplifyInstruction(&Inst, Q)) {
35 if (O.shouldKeep())
36 continue;
37 Inst.replaceAllUsesWith(Simplified);
38 InstToDelete.push_back(&Inst);
44 for (Instruction *I : InstToDelete)
45 I->eraseFromParent();
48 void llvm::simplifyInstructionsDeltaPass(TestRunner &Test) {
49 runDeltaPass(Test, extractInstrFromModule, "Simplifying Instructions");