[llvm] [HashRecognize] Recognize trunc-to-i1 little-endian bit check (PR #213883)
Vito Kortbeek via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 05:41:00 PDT 2026
================
@@ -172,16 +173,25 @@ isSignificantBitCheckWellFormed(const RecurrenceInfo &ConditionalRecurrence,
const Value *L;
const APInt *R;
Instruction *TV, *FV;
- if (!match(SI, m_Select(m_ICmp(Pred, m_Value(L), m_APInt(R)),
- m_Instruction(TV), m_Instruction(FV))))
- return false;
// Match predicate with or without a SimpleRecurrence (the corresponding data
// is LHSAux).
auto MatchPred = m_CombineOr(
m_Specific(ConditionalRecurrence.Phi),
m_c_Xor(m_ZExtOrTruncOrSelf(m_Specific(ConditionalRecurrence.Phi)),
m_ZExtOrTruncOrSelf(m_Specific(SimpleRecurrence.Phi))));
+
+ BinaryOperator *BitShift = ConditionalRecurrence.BO;
+ auto MatchBitShiftXorGenPoly = m_c_Xor(
+ m_Specific(BitShift), m_SpecificInt(*ConditionalRecurrence.ExtraConst));
+ if (!IsBigEndian &&
+ match(SI, m_Select(m_Trunc(MatchPred), MatchBitShiftXorGenPoly,
+ m_Specific(BitShift))))
+ return true;
----------------
vkortbeek-gf wrote:
I think the current version is correct. These are now the two alternative little endian forms:
```llvm
; new trunc to i1 form
%cond = trunc i8 %x to i1
%shift = lshr i16 %crc, 1
%with.poly = xor i16 %shift, -24575
%next = select i1 %cond, i16 %with.poly, i16 %shift
```
```llvm
; (corresponding) original icmp form, there are more
%bit = and i8 %x, 1
%cond = icmp ne i8 %bit, 0
%shift = lshr i16 %crc, 1
%with.poly = xor i16 %shift, -24575
%next = select i1 %cond, i16 %with.poly, i16 %shift
```
The `trunc` matcher validates the complete first form. The later predicate/range checks validate the alternative (original) `icmp` form and don’t apply to `trunc`.
The `trunc` match is a significantly simpler because there are fewer produced `trunc` variations.
https://github.com/llvm/llvm-project/pull/213883
More information about the llvm-commits
mailing list