Index: lib/Transforms/Scalar/GVN.cpp =================================================================== --- lib/Transforms/Scalar/GVN.cpp +++ lib/Transforms/Scalar/GVN.cpp @@ -67,6 +67,7 @@ static cl::opt EnablePRE("enable-pre", cl::init(true), cl::Hidden); static cl::opt EnableLoadPRE("enable-load-pre", cl::init(true)); +static cl::opt DisableZeroCostPHIPRE("disable-phi-pre", cl::init(false)); // Maximum allowed recursion depth. static cl::opt @@ -2529,7 +2530,8 @@ // Don't do PRE when it might increase code size, i.e. when // we would need to insert instructions in more than one pred. - if (NumWithout > 1 || NumWith == 0) + if ((DisableZeroCostPHIPRE && NumWithout != 1) || + ((!DisableZeroCostPHIPRE) && NumWithout > 1) || NumWith == 0) return false; // We may have a case where all predecessors have the instruction,