Yet another attempt to disable DAGCombine for -O0 and optnone for better debugging experience.
Some additional info on the subject can be found in D7181, D8614 and in PR22346.
The previous attempt has been reverted due to the failures in instruction selection, which depends on the transforms done from DAGCombine. DAGCombine calls LegalizeOp that performs transformations such as ConstantPool -> <TargetConstantPool + Wrapper> and others. Their absence breaks instruction selection.
The patch disables combine leaving LegalizeOp enabled to satisfy instruction selection. The dependent tests were adjusted to reflect the changes in the code generated w/o combine.
It also has a fix in ARMISelDAGToDAG.cpp that prevents llc from crashing when compiling the CodeGen/ARM/2010-05-18-LocalAllocCrash.ll test with DAGCombine disabled, as described in PR22346.
I might be missing some important points so would like to have a sharp community's eye on this and hear any concerns / criticism about the patch.
*UPDATE*
The new version of the patch fixes broken FMA lowering on X86 (please find the comment from Michael Kuperstein).
Previously X86 FMA lowering was done at the combine step thereby requiring DAGCombine to get proper target specific FMA nodes. The patch moves this logic to the Legalize step to make FMA lowering independent on DAGCombine. It also adds a new CodeGen/X86/fma-no-dag-combine.ll test.
This broke fma_patterns.ll and other tests that expected operations like a * b - c to be combined into (fma a, b, (fneg c)). The patch was producing vfmadd instead of the expected vfmsub. The reason for this is that FNEG lowering is called before the added FMA lowering. FNEG gets transformed into other nodes making FMA lowering unable to match the pattern for vfmsub. To overcome this, the patch skips FNEG lowering if it is an FMA operand (LowerFABSorFNEG in X86ISelLowering.cpp).
It should be sufficient to test OptLevel here. OptimizeNone should have reset OptLevel for the current function, so you should not need to check the attribute directly.