D108992 added KnownBits handling for 'Quadratic Reciprocity' self-multiplication patterns (bit[1] == 0), which can be used for non-undef values (poison is OK).
This patch adds noundef selfmultiply handling to value tracking so demanded bits patterns can make use of it.
Differential Revision: https://reviews.llvm.org/D117995
}
}
- Known = KnownBits::mul(Known, Known2);
+ bool SelfMultiply = Op0 == Op1;
+ // TODO: SelfMultiply can be poison, but not undef.
+ SelfMultiply &=
+ isGuaranteedNotToBeUndefOrPoison(Op0, Q.AC, Q.CxtI, Q.DT, Depth + 1);
+ Known = KnownBits::mul(Known, Known2, SelfMultiply);
// Only make use of no-wrap flags if we failed to compute the sign bit
// directly. This matters if the multiplication always overflows, in
; CHECK-LABEL: @combine_mul_self_demandedbits_vector(
; CHECK-NEXT: [[TMP1:%.*]] = freeze <4 x i32> [[X:%.*]]
; CHECK-NEXT: [[TMP2:%.*]] = mul <4 x i32> [[TMP1]], [[TMP1]]
-; CHECK-NEXT: [[TMP3:%.*]] = and <4 x i32> [[TMP2]], <i32 -3, i32 -3, i32 -3, i32 -3>
-; CHECK-NEXT: ret <4 x i32> [[TMP3]]
+; CHECK-NEXT: ret <4 x i32> [[TMP2]]
;
%1 = freeze <4 x i32> %x
%2 = mul <4 x i32> %1, %1