Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -8880,13 +8880,11 @@ EVT VT = Op.getValueType(); if (VT.getScalarType() == MVT::i1) { - // Lower i1 truncate to `(x & 1) != 0`. + // Lower i1 truncate to `x != 0`. SDLoc dl(Op); EVT OpVT = Op.getOperand(0).getValueType(); SDValue Zero = DAG.getConstant(0, dl, OpVT); - SDValue One = DAG.getConstant(1, dl, OpVT); - SDValue And = DAG.getNode(ISD::AND, dl, OpVT, Op.getOperand(0), One); - return DAG.getSetCC(dl, VT, And, Zero, ISD::SETNE); + return DAG.getSetCC(dl, VT, Op.getOperand(0), Zero, ISD::SETNE); } if (!VT.isVector() || VT.isScalableVector()) Index: llvm/test/CodeGen/AArch64/sve-trunc.ll =================================================================== --- llvm/test/CodeGen/AArch64/sve-trunc.ll +++ llvm/test/CodeGen/AArch64/sve-trunc.ll @@ -66,7 +66,6 @@ ; CHECK-LABEL: trunc_i64toi1: ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: ptrue p0.d -; CHECK-NEXT: and z0.d, z0.d, #0x1 ; CHECK-NEXT: cmpne p0.d, p0/z, z0.d, #0 ; CHECK-NEXT: ret entry: @@ -78,8 +77,6 @@ ; CHECK-LABEL: trunc_i64toi1_split: ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: ptrue p0.d -; CHECK-NEXT: and z1.d, z1.d, #0x1 -; CHECK-NEXT: and z0.d, z0.d, #0x1 ; CHECK-NEXT: cmpne p1.d, p0/z, z1.d, #0 ; CHECK-NEXT: cmpne p0.d, p0/z, z0.d, #0 ; CHECK-NEXT: uzp1 p0.s, p0.s, p1.s @@ -93,16 +90,12 @@ ; CHECK-LABEL: trunc_i64toi1_split2: ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: ptrue p0.d -; CHECK-NEXT: and z3.d, z3.d, #0x1 -; CHECK-NEXT: and z2.d, z2.d, #0x1 -; CHECK-NEXT: and z1.d, z1.d, #0x1 -; CHECK-NEXT: and z0.d, z0.d, #0x1 ; CHECK-NEXT: cmpne p1.d, p0/z, z3.d, #0 ; CHECK-NEXT: cmpne p2.d, p0/z, z2.d, #0 -; CHECK-NEXT: uzp1 p1.s, p2.s, p1.s -; CHECK-NEXT: cmpne p2.d, p0/z, z1.d, #0 +; CHECK-NEXT: cmpne p3.d, p0/z, z1.d, #0 ; CHECK-NEXT: cmpne p0.d, p0/z, z0.d, #0 -; CHECK-NEXT: uzp1 p0.s, p0.s, p2.s +; CHECK-NEXT: uzp1 p1.s, p2.s, p1.s +; CHECK-NEXT: uzp1 p0.s, p0.s, p3.s ; CHECK-NEXT: uzp1 p0.h, p0.h, p1.h ; CHECK-NEXT: ret entry: @@ -119,18 +112,10 @@ ; CHECK-NEXT: .cfi_escape 0x0f, 0x0c, 0x8f, 0x00, 0x11, 0x10, 0x22, 0x11, 0x08, 0x92, 0x2e, 0x00, 0x1e, 0x22 // sp + 16 + 8 * VG ; CHECK-NEXT: .cfi_offset w29, -16 ; CHECK-NEXT: ptrue p0.d -; CHECK-NEXT: and z7.d, z7.d, #0x1 -; CHECK-NEXT: and z6.d, z6.d, #0x1 -; CHECK-NEXT: and z5.d, z5.d, #0x1 -; CHECK-NEXT: and z4.d, z4.d, #0x1 -; CHECK-NEXT: and z3.d, z3.d, #0x1 -; CHECK-NEXT: and z2.d, z2.d, #0x1 ; CHECK-NEXT: cmpne p1.d, p0/z, z7.d, #0 ; CHECK-NEXT: cmpne p2.d, p0/z, z6.d, #0 ; CHECK-NEXT: cmpne p3.d, p0/z, z5.d, #0 ; CHECK-NEXT: cmpne p4.d, p0/z, z4.d, #0 -; CHECK-NEXT: and z1.d, z1.d, #0x1 -; CHECK-NEXT: and z0.d, z0.d, #0x1 ; CHECK-NEXT: uzp1 p1.s, p2.s, p1.s ; CHECK-NEXT: cmpne p2.d, p0/z, z3.d, #0 ; CHECK-NEXT: uzp1 p3.s, p4.s, p3.s @@ -156,7 +141,6 @@ ; CHECK-LABEL: trunc_i32toi1: ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: ptrue p0.s -; CHECK-NEXT: and z0.s, z0.s, #0x1 ; CHECK-NEXT: cmpne p0.s, p0/z, z0.s, #0 ; CHECK-NEXT: ret entry: @@ -168,7 +152,6 @@ ; CHECK-LABEL: trunc_i16toi1: ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: ptrue p0.h -; CHECK-NEXT: and z0.h, z0.h, #0x1 ; CHECK-NEXT: cmpne p0.h, p0/z, z0.h, #0 ; CHECK-NEXT: ret entry: @@ -180,7 +163,6 @@ ; CHECK-LABEL: trunc_i8toi1: ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: ptrue p0.b -; CHECK-NEXT: and z0.b, z0.b, #0x1 ; CHECK-NEXT: cmpne p0.b, p0/z, z0.b, #0 ; CHECK-NEXT: ret entry: