LLVM  5.0.0
Macros | Functions
X86CmovConversion.cpp File Reference

This file implements a pass that converts X86 cmov instructions into branch when profitable. More...

#include "X86.h"
#include "X86InstrInfo.h"
#include "X86Subtarget.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetSchedule.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Include dependency graph for X86CmovConversion.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "x86-cmov-converter"
 

Functions

 STATISTIC (NumOfSkippedCmovGroups,"Number of unsupported CMOV-groups")
 
 STATISTIC (NumOfCmovGroupCandidate,"Number of CMOV-group candidates")
 
 STATISTIC (NumOfLoopCandidate,"Number of CMOV-conversion profitable loops")
 
 STATISTIC (NumOfOptimizedCmovGroups,"Number of optimized CMOV-groups")
 

Detailed Description

This file implements a pass that converts X86 cmov instructions into branch when profitable.

This pass is conservative, i.e., it applies transformation if and only if it can gaurantee a gain with high confidence.

Thus, the optimization applies under the following conditions:

  1. Consider as a candidate only CMOV in most inner loop, assuming that most hotspots are represented by these loops.
  2. Given a group of CMOV instructions, that are using same EFLAGS def instruction: a. Consider them as candidates only if all have same code condition or opposite one, to prevent generating more than one conditional jump per EFLAGS def instruction. b. Consider them as candidates only if all are profitable to be converted, assuming that one bad conversion may casue a degradation.
  3. Apply conversion only for loop that are found profitable and only for CMOV candidates that were found profitable. a. Loop is considered profitable only if conversion will reduce its depth cost by some thrishold. b. CMOV is considered profitable if the cost of its condition is higher than the average cost of its true-value and false-value by 25% of branch-misprediction-penalty, this to assure no degredassion even with 25% branch misprediction.

Note: This pass is assumed to run on SSA machine code.

Definition in file X86CmovConversion.cpp.

Macro Definition Documentation

#define DEBUG_TYPE   "x86-cmov-converter"

Definition at line 56 of file X86CmovConversion.cpp.

Function Documentation

STATISTIC ( NumOfSkippedCmovGroups  ,
"Number of unsupported CMOV-groups"   
)
STATISTIC ( NumOfCmovGroupCandidate  ,
"Number of CMOV-group candidates"   
)
STATISTIC ( NumOfLoopCandidate  ,
"Number of CMOV-conversion profitable loops"   
)
STATISTIC ( NumOfOptimizedCmovGroups  ,
"Number of optimized CMOV-groups"   
)