On 8/27/26 2:43 AM, wangjue wrote:
From: juewang <[email protected]>
Handle conditional arithmetic wrapped in a sign or zero extension when
the unchanged value is known to have the same extension.
This is missing a ChangeLog.
Good to see you caught the problem with needing the common operand to
have the same extension state as the result of the conditional op. I
made that mistake a few years ago poking at this problem.
Good to also see that you're handling the need to not modify the
original IL in case the transformation fails. The ISCAS team struggled
to get that right and their work in this space never went forward as a
result.
diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc
index add276ceb9b..f28fb38dfc2 100644
--- a/gcc/ifcvt.cc
+++ b/gcc/ifcvt.cc
+
+/* Return true if REG contains an EXT_CODE extension from INNER_MODE before
+ BEFORE. */
+
+static bool
+noce_reg_known_extended_p (rtx reg, rtx_insn *before,
+ enum rtx_code ext_code, machine_mode inner_mode)
+{
+ if (!REG_P (reg) || !before)
+ return false;
+
+ basic_block bb = BLOCK_FOR_INSN (before);
+ for (rtx_insn *insn = prev_nonnote_nondebug_insn (before);
+ insn && BLOCK_FOR_INSN (insn) == bb;
+ insn = prev_nonnote_nondebug_insn (insn))
+ if (modified_in_p (reg, insn))
+ {
+ rtx set = single_set (insn);
+ if (!set || !rtx_equal_p (SET_DEST (set), reg))
+ return false;
+
+ rtx src = SET_SRC (set);
+ return GET_CODE (src) == ext_code
+ && GET_MODE (src) == GET_MODE (reg)
+ && GET_MODE (XEXP (src, 0)) == inner_mode;
+ }
+
+ return false;
Rather than computing this yourself, can't you just check
num_sign_bit_copies and num_nonzero_bits? I would expect that to work
better since we do try to track that data, potentially even through
different forms and operations. So for example if we find t = a &
0x3f. That's not going to be an extension, but we can track sign bit
copies and nonzero bits through such expressions.
That's really the only concern I see; if we can use
num_sign_bit_copies/num_nonzero_bits rather than rolling our own less
effective version here, then that would be meaningfully better. With
that change and a ChangeLog I'm prepared to ACK and install.
jeff