diff --git a/Makefile.in b/Makefile.in
index da4a87f..21d1f60 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -242,7 +242,7 @@ $(NATIVE_BUILD_DIR)/be/be be: be.so
 $(NATIVE_BUILD_DIR)/be/be.so be.so: include libiberty targ_info
 	$(MAKE) -C $(NATIVE_BUILD_DIR)/be
 
-$(NATIVE_BUILD_DIR)/cg/cg.so cg.so: be.so libelf libelfutil libdwarf libunwindP
+$(NATIVE_BUILD_DIR)/cg/cg.so cg.so: wopt.so be.so libelf libelfutil libdwarf libunwindP
 	$(MAKE) -C $(NATIVE_BUILD_DIR)/cg
 
 $(NATIVE_BUILD_DIR)/wopt/wopt.so wopt.so: be.so 
diff --git a/osprey/be/be/driver.cxx b/osprey/be/be/driver.cxx
index 207cd21..237f373 100644
--- a/osprey/be/be/driver.cxx
+++ b/osprey/be/be/driver.cxx
@@ -162,6 +162,7 @@
 #endif
 #include "wn_mp.h"    // for Verify_No_MP()
 #include "comp_decl.h"
+#include "wn_simp.h" 
 
 extern ERROR_DESC EDESC_BE[], EDESC_CG[];
 
@@ -1183,6 +1184,7 @@ Do_WOPT_and_CG_with_Regions (PU_Info *current_pu, WN *pu)
 #endif
     }
  
+        WN_Simplifier_Enable(TRUE);
 #if defined(EMULATE_FLOAT_POINT) && defined(TARG_SL)
  	rwn = WN_Lower(rwn, LOWER_TO_CG | LOWER_FP_EMULATE, alias_mgr, "Lowering to CG/Lowering float point emulate");
 #else
diff --git a/osprey/be/cg/Makefile.gbase b/osprey/be/cg/Makefile.gbase
index 4b75d58..d4f71b5 100644
--- a/osprey/be/cg/Makefile.gbase
+++ b/osprey/be/cg/Makefile.gbase
@@ -210,6 +210,10 @@ ifndef TARG_BE
 TARG_BE = $(TARGDIR)/be
 endif
 
+ifndef TARG_WOPT
+TARG_WOPT = $(TARGDIR)/wopt
+endif
+
 HEADER_DIRS = \
   $(SRC_DIRS)		\
   $(COMMON_STL_DIR)	\
@@ -482,6 +486,7 @@ CG_CXX_SRCS = 		\
   cgssa_build.cxx		\
   cgssa_update.cxx		\
   gpo.cxx       	\
+  lwcfg.cxx             \
   $(DERIVED_SRCS)
 
 ifeq ($(BUILD_TARGET), SL)
@@ -704,6 +709,7 @@ ifndef SKIP_DEP_BUILD
 endif
 ifeq ($(BUILD_OS), LINUX)
 	if ! test -e be.so; then ln -sf $(TARG_BE)/be.so .; fi
+	if ! test -e wopt.so; then ln -sf $(TARG_WOPT)/wopt.so . ; fi
 	if ! test -e be; then ln -sf $(TARG_BE)/be .; fi
 endif
 
@@ -746,25 +752,25 @@ cg_pch_files: $(CG_PCH_OBJS) cg_pch.pch
 cg_gra_pch_files: $(CG_GRA_PCH_OBJS) cg_gra_pch.pch
 
 cg.so:  $(CG_CXX_OBJS) $(CG_C_OBJS) $(CG_PCH_OBJS) $(CG_GRA_PCH_OBJS)\
-	$(BE_CG_DIR)/Exported $(TARG_BE)/be.so \
+	$(BE_CG_DIR)/Exported $(TARG_BE)/be.so $(TARG_WOPT)/wopt.so\
 	$(BE_BE_DIR)/so_locations
 	$(link.c++f) $(UNRESOLVED_FLAGS) $(STD_DSO_LOADOPTS) $(EXPORT_LIST) \
 	$(CG_C_OBJS) $(CG_CXX_OBJS) $(CG_PCH_OBJS) $(CG_GRA_PCH_OBJS)\
-	-o $@ $(TARG_BE)/be.so $(LLDLIBS)
+	-o $@ $(TARG_BE)/be.so $(TARG_WOPT)/wopt.so $(LLDLIBS)
 
 else
  ifeq ($(BUILD_OS), LINUX)
 # dso's must be in same directory
-LINK_DSOS = be.so
+LINK_DSOS = be.so wopt.so
 ifeq ($(BUILD_HOST), IA64)
 ifeq ($(BUILD_COMPILER), SGI)
 STD_DSO_LOADOPTS += -Wl,-relax
 endif
 endif
  else
-LINK_DSOS = $(TARG_BE)/be.so
+LINK_DSOS = $(TARG_BE)/be.so $(TARG_WOPT)/wopt.so
  endif
-cg.so:  $(CG_CXX_OBJS) $(CG_C_OBJS) $(BE_CG_DIR)/Exported $(TARG_BE)/be.so \
+cg.so:  $(CG_CXX_OBJS) $(CG_C_OBJS) $(BE_CG_DIR)/Exported $(TARG_BE)/be.so $(TARG_WOPT)/wopt.so\
 		$(BE_BE_DIR)/so_locations
 	$(link.c++f) $(UNRESOLVED_FLAGS) $(STD_DSO_LOADOPTS) $(EXPORT_LIST) \
 		$(CG_C_OBJS) $(CG_CXX_OBJS) -v \
diff --git a/osprey/be/cg/cg.cxx b/osprey/be/cg/cg.cxx
index 9e644f8..936f0ff 100644
--- a/osprey/be/cg/cg.cxx
+++ b/osprey/be/cg/cg.cxx
@@ -160,6 +160,8 @@
 #include "cgssa_core.h"
 #include "gpo.h"
 
+#include "lwcfg.h"
+
 using namespace CGSSA_NAME;
 
 MEM_POOL MEM_local_region_pool; /* allocations local to processing a region */
@@ -753,6 +755,12 @@ CG_Generate_Code(
   BOOL orig_reuse_temp_tns = Reuse_Temp_TNs;
   Alias_Manager = alias_mgr;
 
+  if (CG_opt_level < 2) {
+    Set_Error_Phase ( "Cfg branch fold" );
+    LWCFG lwcfg(rwn, alias_mgr);
+    rwn = lwcfg.fold_br_cond();
+  }
+
   Set_Error_Phase( "Code Generation" );
   Start_Timer( T_CodeGen_CU );
 
@@ -787,10 +795,10 @@ CG_Generate_Code(
      rse_budget = PU_gp_group(Pu_Table [ST_pu (func_st)]);
      if (rse_budget == 0) DevWarn("FAINT THE RSE BUDGET IS ZERO!");
   }
-#endif
-        
+#endif 
+  
   CG_Region_Initialize ( rwn, alias_mgr );
-
+ 
   Set_Error_Phase ( "Code_Expansion" );
   Start_Timer ( T_Expand_CU );
 
diff --git a/osprey/be/cg/lwcfg.cxx b/osprey/be/cg/lwcfg.cxx
new file mode 100644
index 0000000..d552870
--- /dev/null
+++ b/osprey/be/cg/lwcfg.cxx
@@ -0,0 +1,582 @@
+//
+// The Low Whirl Control-Flow-Graph build up part for CG.
+
+// Copyright (C) 2012 Hewlett-Packard Development Company, L.P. All Rights Reserved.
+
+// Open64 is free software; you can redistribute it and/or modify it 
+// under the terms of the GNU General Public License as published by 
+// the Free Software Foundation; either version 2 of the License, 
+// or (at your option) any later version.
+
+// Open64 is distributed in the hope that it will be useful, but 
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along 
+// with this program; if not, write to the Free SoftwareFoundation, Inc., 
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+// Tracing Flag
+// --ttcgm:0x10000 trace the PU's VL WHIRL before and after fold_condition.
+// --ttcgm:0x20000 trace PU's candidate for lightweight copy-propagation to TRUEBR/FALSEBR.
+// --ttcgm:0x40000 trace the real const-prop to FALSEBR/TRUEBR in VL WHIRL.
+// --ttcgm:0x80000 trace the emit of LWCFG.
+
+#ifdef USE_PCH
+#include "opt_pch.h"
+#endif // USE_PCH
+#pragma hdrstop
+
+
+#ifdef _KEEP_RCS_ID
+#define opt_rvi_CXX	"lwcfg.cxx"
+static char *rcs_id = 	lwcfg_CXX"$Revision: 1.0 $";
+#endif /* _KEEP_RCS_ID */
+
+
+#include "defs.h"
+#include "wn.h"
+#include "wn_simp.h"
+#include "wn_tree_util.h"
+#include "wn_util.h"
+
+#include <vector>
+#include <utility>
+
+// optimizer stuff //
+#include "opt_defs.h"
+#include "opt_base.h"
+#include "opt_config.h"
+#include "opt_bb.h"
+#include "opt_cfg.h"
+#include "region_util.h"	// RID structure
+
+#include "lwcfg.h"
+class LWCFG_REGION {
+  friend class LWCFG_EMIT;
+
+  BB_NODE *_region_start;	// the start of the region
+  BB_NODE *_region_end;		// last block in the region
+  WN      *_prev_wn;		// previous WN that we must follow
+
+  // private constructor so it cannot be used
+  LWCFG_REGION(void);
+  LWCFG_REGION(const LWCFG_REGION&);
+  LWCFG_REGION& operator = (const LWCFG_REGION&);
+
+public:
+  LWCFG_REGION(BB_NODE *region_start, BB_NODE *region_end, WN *prev_wn) :
+    _region_start(region_start),
+    _region_end(region_end),
+    _prev_wn(prev_wn)
+  {
+  }
+
+  BB_NODE *Region_start(void) const { return _region_start; }
+  BB_NODE *Region_end(void) const { return _region_end; }
+  WN      *Prev_wn(void) const { return _prev_wn; }
+}; // end rvie_region class
+
+
+// class for emitting a program.  Note: constructor does all the
+// work.
+//
+class LWCFG_EMIT {
+private:
+  CFG	*_cfg;
+  WN		*_entry_wn;
+  WN		*_first_wn;
+  WN		*_last_wn;
+  MEM_POOL      *_ppool;
+  ALIAS_MANAGER *_alias_mgr;
+  REGION_LEVEL  _region_level;	// the rvi emitter is called for Phase 1
+  				// and Phase 2
+
+  // deal with the creation of regions using a stack of them
+  STACK<LWCFG_REGION *> _region_stack;
+  void     Push_region( BB_NODE *start_region );
+  void     Pop_region( void );
+
+  ALIAS_MANAGER *Alias_Mgr(void) const 
+           { return _alias_mgr; }
+
+  // emit the code
+  void Emit_bb( BB_NODE *bb );
+
+  LWCFG_EMIT( void );		// not used
+  LWCFG_EMIT(const LWCFG_EMIT&);	// not used
+  LWCFG_EMIT& operator = (const LWCFG_EMIT&);
+public:
+  // constructor does everything (to build tree, etc.)
+  LWCFG_EMIT(CFG *cfg, 
+             ALIAS_MANAGER *alias_mgr,
+             MEM_POOL *ppool,
+             REGION_LEVEL region_level);
+  ~LWCFG_EMIT( void ) {}
+
+  // access methods
+  CFG *Cfg( void ) const
+		{ return _cfg; }
+  WN *Entry_wn( void )
+		{ return _entry_wn; }
+  void Set_entry_wn( WN *entry_wn )
+		{ _entry_wn = entry_wn; }
+  WN *First_wn( void )
+		{ return _first_wn; }
+  void Set_first_wn( WN *first_wn )
+		{ _first_wn = first_wn; }
+  WN *Last_wn( void )
+		{ return _last_wn; }
+  void Set_last_wn( WN *last_wn )
+		{ _last_wn = last_wn; }
+};
+
+
+void
+LWCFG_EMIT::Emit_bb( BB_NODE *bb )
+{
+  if (Get_Trace(TP_CG,0x80000) )
+    fprintf( TFile, "LWCFG_EMIT::Emit_bb(BB:%d)\n", bb->Id() );
+
+  if (bb->Kind() == BB_ENTRY && bb->Entrywn()) {
+    const OPCODE fopc = WN_opcode(bb->Entrywn());
+    if ( fopc == OPC_FUNC_ENTRY ) {
+      Set_entry_wn(bb->Entrywn());
+    }
+    else if ( fopc == OPC_ALTENTRY ) {
+      // this becomes a real statement in the block, so just add
+      // it before any others
+      bb->Prepend_wn_after_labels( bb->Entrywn() );
+    }
+    else if ( fopc == OPC_LABEL &&
+	      WN_Label_Is_Handler_Begin(bb->Entrywn()) )
+    {
+      // this is an exception-handler label, and it becomes a real 
+      // statement in the block, so just add it before any others
+      bb->Prepend_wn_after_labels( bb->Entrywn() );
+    }
+#ifdef KEY
+    else if ( fopc == OPC_LABEL &&
+	      LABEL_target_of_goto_outer_block(WN_label_number(bb->Entrywn())))
+    {
+      // this is label being jumped to from a nested function, and it becomes a
+      // real statement in the block, so just add it before any others
+      bb->Prepend_wn_after_labels( bb->Entrywn() );
+    }
+#endif
+  }
+
+  WN *first = bb->Firststmt();
+  WN *last  = bb->Laststmt();
+
+  if ( first == NULL ) {
+    Is_True( last == NULL,
+      ("LWCFG_EMIT::Emit_bb: non-NULL last for BB:%d", bb->Id()) );
+    Is_Trace( Get_Trace(TP_CG,0x80000),	
+              (TFile,"LWCFG_EMIT::Emit_bb, empty BB%d\n",bb->Id()));
+    return;
+  }
+
+  if ( Last_wn() != NULL ) {
+    WN_prev(first) = Last_wn();
+    WN_next(Last_wn()) = first;
+    WN_next(last) = NULL;
+    Set_last_wn( last );
+  }
+  else {
+    // we've just begun, so these are the only statements
+    Set_first_wn( first );
+    Set_last_wn( last );
+  }
+}
+
+
+
+// ====================================================================
+// Handle the creation of regions
+// ====================================================================
+
+void
+LWCFG_EMIT::Push_region( BB_NODE *start_region )
+{
+  BB_REGION *bb_region = start_region->Regioninfo();
+  BB_NODE *end_region = bb_region->Region_end();
+
+  LWCFG_REGION *rvie_region = 
+    CXX_NEW(LWCFG_REGION(start_region, end_region, Last_wn()), 
+	    _ppool);
+
+  _region_stack.Push(rvie_region);
+}
+
+void
+LWCFG_EMIT::Pop_region( void )
+{
+  LWCFG_REGION *rvie_region = _region_stack.Pop();
+  WN *prev_wn = rvie_region->Prev_wn();
+  WN *last_region_wn = Last_wn();
+  WN *first_region_wn= prev_wn ? WN_next(prev_wn) : First_wn();
+  BB_REGION *bb_region = rvie_region->Region_start()->Regioninfo();
+
+  // if it is an empty EH Guard region, put a comment in there
+  if (RID_TYPE_guard(bb_region->Rid()) && first_region_wn == NULL &&
+      (last_region_wn == NULL || last_region_wn == prev_wn)){
+    first_region_wn = last_region_wn = WN_CreateComment("EH GUARD REGION");
+  }
+
+  if (first_region_wn == NULL &&
+      (last_region_wn == NULL || last_region_wn == prev_wn))
+  {
+    // Nothing (empty stmt sequence) was emitted for this region.  The code
+    // here is loosely based on EMITTER::Gen_wn() in opt_emit.cxx.
+    //
+    BB_NODE *rstart = bb_region->Region_start();
+
+    // Leave the LWCFG_REGION in a consistent state, and kill any pragmas
+    // emitted before we knew the region was empty.
+    //
+    last_region_wn = NULL;
+    rstart->Set_firststmt(NULL);
+    rstart->Set_laststmt(NULL);
+    
+    // region is empty, don't emit it.
+    //
+    RID_Delete2(bb_region->Rid());
+  }
+  else
+  {
+    // create the region and the body
+    WN *region_body = WN_CreateBlock();
+    WN_first(region_body) = first_region_wn;
+    WN_last(region_body)  = last_region_wn;
+    WN *region_wn = WN_CreateRegion(REGION_type_to_kind(bb_region->Rid()),
+				    region_body,
+				    bb_region->Region_pragma_list(),
+				    bb_region->Region_exit_list(),
+				    RID_id(bb_region->Rid()),
+				    bb_region->Ereg_supp());
+
+     // no need to go through pragma block because LWCFG doesn't deal with
+     // EH regions
+  
+     // update the wn list so this region node replaces the statements
+     // it put into its body.
+    if ( first_region_wn != NULL )
+      WN_prev(first_region_wn) = NULL;
+    Is_True( last_region_wn == NULL || WN_next(last_region_wn) == NULL,
+	     ("LWCFG_EMIT::Pop_region: last_region_wn has non-null next") );
+
+    if ( prev_wn != NULL )
+      WN_next(prev_wn) = region_wn;
+    WN_prev(region_wn) = prev_wn;
+    Set_last_wn(region_wn);
+    // do we become the first statement?
+    if ( first_region_wn == First_wn() )
+      Set_first_wn(region_wn);
+
+    // update the RID
+    REGION_emit(bb_region->Rid(), region_wn, _region_level,
+		bb_region->Region_num_exits(), bb_region->Region_line_num());
+  }
+}
+
+// ====================================================================
+// Constructor for LWCFG_EMIT actually does all of the work
+// ====================================================================
+
+LWCFG_EMIT::LWCFG_EMIT(CFG *cfg,
+                       ALIAS_MANAGER *alias_mgr,
+                       MEM_POOL *ppool,
+                       REGION_LEVEL region_level) : 
+  _cfg(cfg), 
+  _ppool(ppool),
+  _region_stack(ppool)
+{
+  // init fields first
+  _entry_wn = NULL;
+  _first_wn = NULL;
+  _last_wn  = NULL;
+  _alias_mgr = alias_mgr;
+  _region_level = region_level;
+
+  // process all of the blocks, linking them up as necessary
+  CFG_ITER cfg_iter(Cfg());
+  BB_NODE *bb;
+  FOR_ALL_NODE( bb, cfg_iter, Init() ) {
+
+    Is_Trace(Get_Trace(TP_CG, 0x80000),(TFile,"----- BB%d -----\n",bb->Id()));
+
+    // do we have a region to build up?
+    if ( bb->Kind() == BB_REGIONSTART ) {
+      Is_Trace(Get_Trace(TP_CG, 0x80000),
+	       (TFile,"LWCFG_EMIT, Push_region BB%d\n",bb->Id()));
+      Push_region(bb);
+    }
+
+    Emit_bb( bb );
+
+    // did we just finish a region?
+    while ( _region_stack.Elements() > 0 && 
+	    _region_stack.Top()->Region_end() == bb )
+    {
+      Is_Trace(Get_Trace(TP_CG, 0x80000), (TFile,"LWCFG_EMIT, Pop_region\n"));
+      Pop_region();
+    }
+  }
+
+  // we should have cleared off the stack of regions
+  Is_True( _region_stack.Elements() == 0,
+    ("LWCFG_EMIT::LWCFG_EMIT: region stack not empty") );
+
+  // this routine is used by the main emitter and rvi emitter to find
+  // the first bb with code in it.
+  BB_NODE *entry_bb = Cfg()->Find_entry_bb();
+  if (entry_bb->Kind() == BB_ENTRY) {
+    if ( Entry_wn() != NULL ) {
+      WN *block = WN_CreateBlock();
+      WN_first(block) = First_wn();
+      WN_last(block) = Last_wn();
+      WN_Set_Linenum( block, WN_Get_Linenum(Entry_wn()) );
+
+      const OPCODE eopc = WN_opcode(Entry_wn());
+      if ( eopc == OPC_FUNC_ENTRY ) {
+	WN_func_body(Entry_wn()) = block;
+	REGION_emit(Cfg()->Rid(), Entry_wn(), _region_level, 1, 0);
+      } else {
+	FmtAssert( FALSE, ("LWCFG_EMIT::LWCFG_EMIT: Can't handle entry %s",
+			   OPCODE_name(eopc)) );
+      }
+    }
+  } else {
+    Is_True(entry_bb->Kind() == BB_REGIONSTART,
+	    ("LWCFG_EMIT::LWCFG_EMIT, unknown entry kind %s",
+	     entry_bb->Kind_name()));
+    Set_entry_wn(First_wn());
+    Is_True(REGION_consistency_check(Entry_wn()),
+	    ("LWCFG_EMIT::LWCFG_EMIT, inconsistent region"));
+  }
+}
+
+
+LWCFG::LWCFG(WN *rwn, ALIAS_MANAGER *alias_mgr):
+  _rwn(rwn), _alias_mgr(alias_mgr) {
+
+  MEM_POOL_Initialize( &_ppool, "lwcfg_ppool", FALSE);
+  MEM_POOL_Initialize( &_lpool, "lwcfg_lpool", FALSE);
+  MEM_POOL_Initialize( &_cfg_pool, "lwcfg_cfgpool", FALSE);
+
+  _PU_printed = FALSE;
+  _cfg = NULL;
+  _PU_name = ST_name(Get_Current_PU_ST());
+}
+
+LWCFG::~LWCFG(void) {
+
+  MEM_POOL_Delete( &_cfg_pool);
+  MEM_POOL_Delete( &_lpool);
+  MEM_POOL_Delete( &_ppool);
+
+}
+
+BOOL LWCFG::pair_cprop_test(WN *to, WN* from) {
+  
+  FmtAssert(WN_operator(to) == OPR_FALSEBR ||
+            WN_operator(to) == OPR_TRUEBR,
+            ("error, to OPR_FALSEBR/OPR_TRUEBR expected!"));
+
+  FmtAssert(WN_operator(from) == OPR_STID, 
+            ("Error, from OPR_STID expected!"));
+
+  BOOL result = FALSE;
+
+  WN_TREE_CONTAINER<PRE_ORDER> lpre(to);
+  WN_TREE_CONTAINER<PRE_ORDER> :: iterator lipre;
+  for ( lipre = lpre.begin() ; lipre != lpre.end() ; ++ lipre) {
+    WN * wn=lipre.Wn();
+    for(INT i = 0; i< WN_kid_count(wn); i++) {
+      WN* load_expr= WN_kid(wn,i);
+      OPERATOR opr = WN_operator(load_expr);
+      if (opr == OPR_LDID &&
+          Is_Local_Symbol(WN_st(load_expr)) &&
+          (WN_st_idx(load_expr) == WN_st_idx(from)) &&
+          WN_rtype(load_expr) == WN_desc(from))  {
+        Prop_pair().push_back(std::make_pair(std::make_pair(wn, i), from));
+        result = TRUE;
+      }
+    }
+  }
+  return result;
+}
+  
+void LWCFG::do_real_cprop(void) {
+  kid_vector::iterator it = Prop_pair().begin();
+  for(; it != Prop_pair().end(); it ++) {
+    if (Get_Trace (TP_CG,0x40000)) {
+      if (! PU_printed()) {
+        fprintf(TFile, "In PU %s\n", PU_name());
+        Set_PU_printed();
+      }
+      fdump_tree(TFile, (*it).second);
+      fprintf(TFile,"be copy propagated to:\n");
+      fdump_tree(TFile, (*it).first.first);
+      fprintf(TFile, "\n");
+    }
+    WN_kid((*it).first.first, (*it).first.second) = WN_CopyNode(WN_kid((*it).second,0));
+  }
+}
+
+
+void LWCFG::pair_cprop_test_for_succeedings(BB_NODE * parent, WN* from) {
+
+  BB_LIST_ITER bb_ps_iter;
+  BB_NODE *succ,*pred;
+  FOR_ALL_ELEM( succ, bb_ps_iter, Init(parent->Succ()) ) {
+
+    WN *first = succ->Firststmt();
+    WN *last = succ->Laststmt();
+    
+    if ( first == NULL ) {
+      Is_True( last == NULL,
+                 ("Error, first NULL while last not NULL for BB:%d", succ->Id()) );
+      continue;
+    }
+
+    if ( last != NULL) {
+      const OPCODE   opc = WN_opcode(last);
+      const OPERATOR opr = OPCODE_operator(opc);
+      if ((opr == OPR_FALSEBR ||
+           opr == OPR_TRUEBR) &&
+          (first == last))
+        if (pair_cprop_test(last, from))
+            pair_cprop_test_for_succeedings(succ, from);
+    }
+  }
+}
+
+void LWCFG::do_test_cprop(void) {
+
+  CFG_ITER cfg_iter(Cfg());
+  BB_NODE *bb;
+
+  FOR_ALL_NODE( bb, cfg_iter, Init() ) {
+
+      WN *first = bb->Firststmt();
+      WN *last  = bb->Laststmt();
+
+      if ( first == NULL ) {
+        Is_True( last == NULL,
+                 ("LWCFG_EMIT::Emit_bb: non-NULL last for BB:%d", bb->Id()) );
+        continue;
+      }
+
+      if ( last != NULL) {
+        const OPCODE   opc = WN_opcode(last);
+        const OPERATOR opr = OPCODE_operator(opc);
+        if ((opr == OPR_FALSEBR ||
+             opr == OPR_TRUEBR) &&
+            (first != last) &&
+            (WN_operator(WN_prev(last)) == OPR_STID)) {
+          WN_Simplifier_Enable(TRUE);
+          WN_kid(WN_prev(last),0) =
+            WN_Simplify_Rebuild_Expr_Tree( WN_kid(WN_prev(last),0),
+                                           Alias_Mgr());
+          if (WN_operator(WN_kid(WN_prev(last),0)) == OPR_INTCONST)
+            if (pair_cprop_test(last, WN_prev(last))) {
+              if (Get_Trace (TP_CG,0x20000)) {
+                if (! PU_printed()) {
+                  fprintf(TFile, "IN PU %s,", PU_name());
+                  Set_PU_printed();
+                }
+                fprintf(TFile, "WN statements:\n");
+                fdump_tree(TFile, WN_prev(last));
+                fdump_tree(TFile, last);
+                fprintf(TFile, "get the chance do to lightweight copy propagation.\n");
+              }
+              pair_cprop_test_for_succeedings(bb,WN_prev(last));
+            }
+        }
+      }
+  }
+}
+
+void LWCFG::do_br_cond_fold(void) {
+
+  CFG_ITER cfg_iter(Cfg());
+  BB_NODE *bb;
+
+  FOR_ALL_NODE( bb, cfg_iter, Init() ) {
+
+      WN *first = bb->Firststmt();
+      WN *last  = bb->Laststmt();
+
+      if ( first == NULL ) {
+        Is_True( last == NULL,
+                 ("LWCFG_EMIT::Emit_bb: non-NULL last for BB:%d", bb->Id()) );
+        continue;
+      }
+
+      if ( last != NULL) {
+        const OPCODE   opc = WN_opcode(last);
+        const OPERATOR opr = OPCODE_operator(opc);
+        if (opr == OPR_FALSEBR ||
+            opr == OPR_TRUEBR) {
+          WN_Simplifier_Enable(TRUE);
+          WN_kid(last,0) =
+            WN_Simplify_Rebuild_Expr_Tree( WN_kid(last, 0),
+                                           Alias_Mgr());
+        }
+      }
+  }
+
+}
+
+
+WN* LWCFG::fold_br_cond(void) {
+
+  if (Get_Trace (TP_CG,0x10000)) {
+    fprintf(TFile, "PU %s\n", PU_name());
+    fdump_tree(TFile, rwn());
+  }
+  
+  WN* new_rwn = NULL;
+  CFG cfg( ppool(), lpool());
+  Set_Cfg(&cfg);
+    
+  cfg.Create(rwn(), TRUE/*lower_fully*/, TRUE/*calls_break*/,
+             RL_LWCFG/*this is Low Whir CFG phase*/, NULL/*stab*/,
+             FALSE/*tail-rec*/,
+             cfg_pool());
+
+  // Firstly, Try to detect the chances for const prop
+  do_test_cprop();
+
+  if (Has_cprop_pairs()) { // Yes, we get the chance of const prop
+      
+    // Do const prop
+    do_real_cprop();
+
+    // fold the conditions after cprop.
+    do_br_cond_fold();
+
+    // Emit Out
+    LWCFG_EMIT emitter( Cfg(), Alias_Mgr(), ppool(), RL_LWCFG );
+    new_rwn = emitter.Entry_wn();
+    if (Get_Trace (TP_CG, 0x10000)) {
+      fprintf(TFile, "PU %s: changed to\n", PU_name());
+      fdump_tree(TFile, new_rwn);
+    }
+  } else { // Otherwise, we still do br_cond_fold
+    do_br_cond_fold();
+    if (Get_Trace (TP_CG,0x10000)) {
+      fprintf(TFile, "PU %s: no change\n", PU_name());
+    }
+      
+    // Emit Out
+    LWCFG_EMIT emitter( Cfg(), Alias_Mgr(), ppool(), RL_LWCFG );
+    new_rwn = emitter.Entry_wn();
+  }
+
+  return new_rwn;
+}
+
diff --git a/osprey/be/cg/lwcfg.h b/osprey/be/cg/lwcfg.h
new file mode 100644
index 0000000..bf84a1d
--- /dev/null
+++ b/osprey/be/cg/lwcfg.h
@@ -0,0 +1,107 @@
+// The Low Whirl Control-Flow-Graph build up header for CG.
+
+// Copyright (C) 2012 Hewlett-Packard Development Company, L.P. All Rights Reserved.
+
+// Open64 is free software; you can redistribute it and/or modify it 
+// under the terms of the GNU General Public License as published by 
+// the Free Software Foundation; either version 2 of the License, 
+// or (at your option) any later version.
+
+// Open64 is distributed in the hope that it will be useful, but 
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along 
+// with this program; if not, write to the Free SoftwareFoundation, Inc., 
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+
+#ifndef lwcfg_INCLUDED
+#define lwcfg_INCLUDED	"lwcfg.h"
+
+#include "defs.h"
+#include "wn.h"
+
+#include "cxx_base.h"
+#include "region_util.h"	// RID structure
+
+class BB_NODE;
+class CFG;
+class ALIAS_MANAGER;
+
+
+
+class LWCFG { //Low Whirl Control-Flow-Graph
+private:
+  char *_PU_name;
+  CFG	*_cfg;
+  WN *_rwn;
+  BOOL _PU_printed ;
+  ALIAS_MANAGER *_alias_mgr;
+
+  typedef std::pair<pair<WN*, INT>, WN *> kid_pair;
+  typedef mempool_allocator<kid_pair> allocator_type;
+  typedef std::vector<kid_pair, allocator_type> kid_vector;
+  kid_vector prop_pair;
+
+  MEM_POOL _ppool;
+  MEM_POOL _lpool;
+  MEM_POOL _cfg_pool;
+
+  MEM_POOL* ppool(void) { return &_ppool; }
+
+  MEM_POOL* lpool(void) { return &_lpool; }
+
+  MEM_POOL* cfg_pool(void) { return &_cfg_pool; }
+
+  ALIAS_MANAGER *Alias_Mgr(void) const { return _alias_mgr; }
+
+  WN* rwn() { return _rwn; }
+
+  void Set_PU_printed(void) { _PU_printed = TRUE;   }
+
+  BOOL PU_printed(void) { return _PU_printed; }
+
+  kid_vector& Prop_pair(void) { return prop_pair; }
+
+  // Do we find the const propgation pairs?
+  BOOL Has_cprop_pairs(void) { return prop_pair.size(); }
+
+  CFG *Cfg(void) const{ return _cfg; }
+
+  void Set_Cfg(CFG* cfg){ _cfg = cfg; }
+
+  char *PU_name(void) { return _PU_name; }
+
+
+  void do_test_cprop(void); //test const propagation to BR conditions
+
+  void do_real_cprop(void); // do real const prop to BR conditions
+
+  void do_br_cond_fold(void); // fold the br condition after const prop
+
+  // test the pair of STID/FLASEBR(TRUEBR) whether the 
+  // candidate for const prop.
+  BOOL pair_cprop_test(WN *to, WN* from) ; 
+
+  // continue to find more targets for the const prop
+  // in the succeeding BasicBlocks.
+  void pair_cprop_test_for_succeedings(BB_NODE * parent, WN* from);
+
+  LWCFG( void );		// not used
+  LWCFG(const LWCFG&);	// not used
+  LWCFG operator = (const LWCFG&); //not used
+
+
+public:
+  // constructor does everything (to build tree, etc.)
+  LWCFG(WN *tree, ALIAS_MANAGER *alias_mgr);
+  ~LWCFG( void );
+
+  // extern method: fold_br_cond
+  WN* fold_br_cond(void) ;
+
+};
+
+#endif
diff --git a/osprey/be/opt/opt_cfg.cxx b/osprey/be/opt/opt_cfg.cxx
index 4301538..7d1194f 100644
--- a/osprey/be/opt/opt_cfg.cxx
+++ b/osprey/be/opt/opt_cfg.cxx
@@ -3244,6 +3244,30 @@ CFG::Add_one_stmt( WN *wn, END_BLOCK *ends_bb )
     Add_one_compgoto_stmt( wn, ends_bb );
     break;
 
+    // OPR_XGOTO occurs in the L WHIRL CFG building
+  case OPR_XGOTO: 
+    {
+      WN * goto_wn = WN_first(WN_kid1(wn));
+      for (int i = 0; i < WN_num_entries(wn); i++ ) {
+        FmtAssert ((goto_wn && WN_opcode(goto_wn) == OPC_GOTO),
+                   ("XGOTO block doesn't have goto's? (%d)", WN_opcode(wn)));
+        label_bb = Get_bb_from_label( WN_label_number(goto_wn) );
+        if (label_bb == NULL) {
+          label_bb = Create_bb(); // this label_bb is filled in later
+          Append_label_map(WN_label_number(goto_wn), label_bb); // add to label map
+        }
+        FmtAssert((label_bb), 
+                  ("CFG XGOTO: unable to creaate label_bb"));
+        Connect_predsucc(_current_bb, label_bb);
+        goto_wn = WN_next(goto_wn);
+      }
+      Append_wn_in(_current_bb, wn);
+      if (ends_bb) {
+        *ends_bb = END_BREAK;
+      }
+      break;
+    }
+
   case OPR_CALL:
   case OPR_ICALL:
   case OPR_PICCALL:
diff --git a/osprey/be/region/region_util.cxx b/osprey/be/region/region_util.cxx
index 6badf83..13d3db5 100644
--- a/osprey/be/region/region_util.cxx
+++ b/osprey/be/region/region_util.cxx
@@ -1057,6 +1057,7 @@ char *RID_level_str(RID *rid)
     case RL_MAINOPT:	strcpy(buff,"RL_MAINOPT");	break;
     case RL_RVI1:	strcpy(buff,"RL_RVI1");		break;
     case RL_RVI2:	strcpy(buff,"RL_RVI2");		break;
+    case RL_LWCFG:      strcpy(buff,"RL_LWCFG");        break;
     case RL_CG:		strcpy(buff,"RL_CG");		break;
     case RL_CGSCHED:	strcpy(buff,"RL_CGSCHED");	break;
     default:
diff --git a/osprey/be/region/region_util.h b/osprey/be/region/region_util.h
index c7c8ea5..e47f1b6 100644
--- a/osprey/be/region/region_util.h
+++ b/osprey/be/region/region_util.h
@@ -98,6 +98,7 @@ typedef	enum {
   RL_MAINOPT,	/* processed by Mainopt emitter			*/
   RL_RVI1,	/* processed by RVI emitter (phase 1)		*/
   RL_RVI2,	/* processed by RVI emitter (phase 2)		*/
+  RL_LWCFG,     /* processed by Low Whirl CFG                   */
   RL_CG,        /* processed to the beginning of CG		*/
   RL_CGSCHED,   /* processed past CG scheduling			*/
   RL_LAST	/* > last legal value				*/
