-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[InstCombine] Remove the canonicalization of trunc
to i1
#84628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
59e41d9
55ace09
64fc00c
6b3ae69
fcaafc3
ad99d1f
4015d83
6594005
f905604
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -734,19 +734,26 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) { | |
|
||
if (DestWidth == 1) { | ||
Value *Zero = Constant::getNullValue(SrcTy); | ||
if (DestTy->isIntegerTy()) { | ||
// Canonicalize trunc x to i1 -> icmp ne (and x, 1), 0 (scalar only). | ||
// TODO: We canonicalize to more instructions here because we are probably | ||
// lacking equivalent analysis for trunc relative to icmp. There may also | ||
// be codegen concerns. If those trunc limitations were removed, we could | ||
// remove this transform. | ||
Value *And = Builder.CreateAnd(Src, ConstantInt::get(SrcTy, 1)); | ||
return new ICmpInst(ICmpInst::ICMP_NE, And, Zero); | ||
} | ||
|
||
// For vectors, we do not canonicalize all truncs to icmp, so optimize | ||
// patterns that would be covered within visitICmpInst. | ||
|
||
dtcxzyw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Value *X; | ||
const APInt *C1; | ||
Constant *C2; | ||
if (match(Src, m_OneUse(m_LShr(m_Shl(m_Power2(C1), m_Value(X)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide the alive2 proof. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, it's https://alive2.llvm.org/ce/z/6Frpdc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could actually be any right shift: https://alive2.llvm.org/ce/z/vmPhjM There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (see |
||
m_ImmConstant(C2))))) { | ||
Constant *Width = ConstantInt::get( | ||
SrcTy, APInt(SrcWidth, SrcTy->getScalarSizeInBits())); | ||
if (ConstantExpr::getICmp(ICmpInst::ICMP_UGE, C2, Width)->isNullValue()) { | ||
// iff C1 is pow2 and C2 < BitWidth: | ||
// trunc ((C1 << X) >> C2) to i1 -> X == (C2-cttz(C1)) | ||
Constant *Log2C1 = ConstantInt::get(SrcTy, C1->exactLogBase2()); | ||
Constant *CmpC = ConstantExpr::getSub(C2, Log2C1); | ||
return new ICmpInst(ICmpInst::ICMP_EQ, X, CmpC); | ||
} | ||
} | ||
|
||
Constant *C; | ||
if (match(Src, m_OneUse(m_LShr(m_Value(X), m_Constant(C))))) { | ||
// trunc (lshr X, C) to i1 --> icmp ne (and X, C'), 0 | ||
|
@@ -763,6 +770,14 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) { | |
Value *And = Builder.CreateAnd(X, Builder.CreateOr(MaskC, One)); | ||
return new ICmpInst(ICmpInst::ICMP_NE, And, Zero); | ||
} | ||
|
||
{ | ||
const APInt *C; | ||
if (match(Src, m_Shl(m_APInt(C), m_Value(X))) && (*C)[0] == 1) { | ||
// trunc (C << X) to i1 --> X == 0, where C is odd | ||
return new ICmpInst(ICmpInst::Predicate::ICMP_EQ, X, Zero); | ||
} | ||
} | ||
} | ||
|
||
Value *A, *B; | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.