Revert "[VPlan] Remove redundant x && (y && x) -> x && y combine (#213219)" (#213405)

This reverts commit 8db13de265.

Logical ands block poison, and commuting the operands doesn't preserve
it
This commit is contained in:
Luke Lau 2026-08-01 12:33:50 +08:00 committed by GitHub
parent cfb2eab54d
commit 4d8c8ff54e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View file

@ -1188,10 +1188,16 @@ static bool simplifyLogicalRecipe(VPSingleDefRecipe *Def, VPBuilder &Builder,
}
// x && (x && y) -> x && y
if (match(Def, m_c_LogicalAnd(m_VPValue(X),
m_VPValue(Z, m_c_LogicalAnd(m_Deferred(X),
m_VPValue()))))) {
Def->replaceAllUsesWith(Z);
if (match(Def, m_LogicalAnd(m_VPValue(X),
m_LogicalAnd(m_Deferred(X), m_VPValue())))) {
Def->replaceAllUsesWith(Def->getOperand(1));
return true;
}
// x && (y && x) -> x && y
if (match(Def, m_LogicalAnd(m_VPValue(X),
m_LogicalAnd(m_VPValue(Y), m_Deferred(X))))) {
Def->replaceAllUsesWith(Builder.createLogicalAnd(X, Y));
return true;
}

View file

@ -143,8 +143,7 @@ define void @logical_and_inner_commute(ptr noalias %p, ptr noalias %q, ptr noali
; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i32>, ptr [[TMP3]], align 4
; CHECK-NEXT: [[TMP4:%.*]] = trunc <4 x i32> [[WIDE_LOAD]] to <4 x i1>
; CHECK-NEXT: [[TMP5:%.*]] = trunc <4 x i32> [[WIDE_LOAD1]] to <4 x i1>
; CHECK-NEXT: [[TMP6:%.*]] = select <4 x i1> [[TMP4]], <4 x i1> [[TMP5]], <4 x i1> zeroinitializer
; CHECK-NEXT: [[TMP7:%.*]] = select <4 x i1> [[TMP6]], <4 x i1> [[TMP4]], <4 x i1> zeroinitializer
; CHECK-NEXT: [[TMP7:%.*]] = select <4 x i1> [[TMP4]], <4 x i1> [[TMP5]], <4 x i1> zeroinitializer
; CHECK-NEXT: [[TMP8:%.*]] = zext <4 x i1> [[TMP7]] to <4 x i32>
; CHECK-NEXT: [[TMP9:%.*]] = getelementptr i32, ptr [[R]], i32 [[INDEX]]
; CHECK-NEXT: store <4 x i32> [[TMP8]], ptr [[TMP9]], align 4