- tarval *v;
- if ( (tarval_classify ((v = computed_value (a))) == -1)
- || (tarval_classify ((v = computed_value (b))) == -1)) {
- res = v;
- }
- }
- break;
- case iro_Eor:
- if ((ta != tarval_bad) && (tb != tarval_bad)) {
- res = tarval_eor (ta, tb);
- }
- break;
- case iro_Not:
- if ((ta != tarval_bad)) {
- res = tarval_not (ta);
- }
- break;
- case iro_Shl:
- if ((ta != tarval_bad) && (tb != tarval_bad)) {
- res = tarval_shl (ta, tb);
- }
- break;
- case iro_Shr:
- if ((ta != tarval_bad) && (tb != tarval_bad)) {
- res = tarval_shr (ta, tb);
- }
- break;
- case iro_Shrs:
- if ((ta != tarval_bad) && (tb != tarval_bad)) {
- res = tarval_shrs (ta, tb);
- }
- break;
- case iro_Rot:
- if ((ta != tarval_bad) && (tb != tarval_bad)) {
- /*res = tarval_rot (ta, tb)*/;
- }
- break;
- case iro_Conv:
- if (ta != tarval_bad) {
- res = tarval_convert_to (ta, get_irn_mode (n));
- }
- break;
- case iro_Proj: /* iro_Cmp */
- {
- ir_node *aa, *ab;
-
- a = get_Proj_pred(n);
- /* Optimize Cmp nodes.
- This performs a first step of unreachable code elimination.
- Proj can not be computed, but folding a Cmp above the Proj here is
- not as wasteful as folding a Cmp into a Tuple of 16 Consts of which
- only 1 is used.
- There are several case where we can evaluate a Cmp node:
- 1. The nodes compared are both the same. If we compare for
- equal, greater equal, ... this will return true, else it
- will return false. This step relies on cse.
- 2. The predecessors of Cmp are target values. We can evaluate
- the Cmp.
- 3. The predecessors are Allocs or void* constants. Allocs never
- return NULL, they raise an exception. Therefore we can predict
- the Cmp result. */
- if (get_irn_op(a) == op_Cmp) {
- aa = get_Cmp_left(a);
- ab = get_Cmp_right(a);
- if (aa == ab) { /* 1.: */
- /* This is a tric with the bits used for encoding the Cmp
- Proj numbers, the following statement is not the same:
- res = new_tarval_from_long ((get_Proj_proj(n) == Eq), mode_b) */
- res = new_tarval_from_long ((get_Proj_proj(n) & Eq), mode_b);
- } else {
- tarval *taa = computed_value (aa);
- tarval *tab = computed_value (ab);
- if ((taa != tarval_bad) && (tab != tarval_bad)) { /* 2.: */
- /* strange checks... */
- pnc_number flags = tarval_cmp (taa, tab);
- if (flags != False) {
- res = new_tarval_from_long (get_Proj_proj(n) & flags, mode_b);
- }
- } else { /* check for 3.: */
- ir_node *aaa = skip_nop(skip_Proj(aa));
- ir_node *aba = skip_nop(skip_Proj(ab));
- if ( ( (/* aa is ProjP and aaa is Alloc */
- (get_irn_op(aa) == op_Proj)
- && (mode_is_reference(get_irn_mode(aa)))
- && (get_irn_op(aaa) == op_Alloc))
- && ( (/* ab is constant void */
- (get_irn_op(ab) == op_Const)
- && (mode_is_reference(get_irn_mode(ab)))
- && (get_Const_tarval(ab) == get_mode_null(get_irn_mode(ab))))
- || (/* ab is other Alloc */
- (get_irn_op(ab) == op_Proj)
- && (mode_is_reference(get_irn_mode(ab)))
- && (get_irn_op(aba) == op_Alloc)
- && (aaa != aba))))
- || (/* aa is void and aba is Alloc */
- (get_irn_op(aa) == op_Const)
- && (mode_is_reference(get_irn_mode(aa)))
- && (get_Const_tarval(aa) == get_mode_null(get_irn_mode(aa)))
- && (get_irn_op(ab) == op_Proj)
- && (mode_is_reference(get_irn_mode(ab)))
- && (get_irn_op(aba) == op_Alloc)))
- /* 3.: */
- res = new_tarval_from_long (get_Proj_proj(n) & Ne, mode_b);
- }
- }
- } else if (get_irn_op(a) == op_DivMod) {
- ta = value_of(get_DivMod_left(a));
- tb = value_of(get_DivMod_right(a));
- if ((ta != tarval_bad) && (tb != tarval_bad) && (get_irn_mode(a) == get_irn_mode(b))) {
- if (tb == get_mode_null(get_tarval_mode(tb))) break; /* div by zero: return tarval_bad */
- if (get_Proj_proj(n)== 0) /* Div */
- res = tarval_div(ta, tb);
- else /* Mod */
- res = tarval_mod(ta, tb);