Atorvastatin belongs to HMG Co-A reductase inhibitors whereas gemfibrozil belongs to fibrates.
Both the drugs decrease lipid levels but their selectivity is somewhat different. For example atorvastatin mainly shows action on LDL and HDL. It decreases LDL levels and increases HDL levels.
On the other hand, fibrates mainly effect triglyceride and VLDL levels. They have minimum effect on LDL and HDL levels.
So when we want to decrease LDL levels and increase LDL levels statins are prescribed. For example in type IIa dyslipidemia LDL levels are increased where statins are drug of choice.
Similarly, if we want to decrease triglyceride and VLDL levels, fibrates are prescribed. For example, in type IV dyslipidemia triglyceride levels are mainly increased where fibrates are drug of choice.
In few of the situations like type IIb dyslipidemia, LDL, triglyceride and VLDL levels are increased. In such situations we should use combination of drugs which effect both LDL and VLDL.
But statins should not be combined with fibrates.
The reason is due to their similar effect on muscle. Both statins and fibrates cause rhabdomyolysis leading to muscle breakdown and intense muscle pain.
In such cases statin can be combined with nicotinic acid the later decreases VLDL and triglyceride levels.
Here is a video explaining in detail about this interaction.