[llvm] [InstCombine] Remove the canonicalization of `trunc` to `i1` (PR #84628)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 21 14:35:09 PDT 2024


================
@@ -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.
+
     Value *X;
+    const APInt *C1;
+    Constant *C2;
+    if (match(Src, m_OneUse(m_LShr(m_Shl(m_Power2(C1), m_Value(X)),
----------------
goldsteinn wrote:

Could actually be any right shift: https://alive2.llvm.org/ce/z/vmPhjM

https://github.com/llvm/llvm-project/pull/84628


More information about the llvm-commits mailing list