diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 64f2c4c571d40..3b9f47702cafb 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -2918,7 +2918,7 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) { // SIGN_EXTEND_INREG does not guarantee that the high bits are already zero. // TODO: Do this for vectors too? - if (ExtraVT.getSizeInBits() == 1) { + if (ExtraVT.isScalarInteger() && ExtraVT.getSizeInBits() == 1) { SDValue One = DAG.getConstant(1, dl, VT); SDValue And = DAG.getNode(ISD::AND, dl, VT, Node->getOperand(0), One); SDValue Zero = DAG.getConstant(0, dl, VT); diff --git a/llvm/test/CodeGen/AArch64/sve-sext-zext.ll b/llvm/test/CodeGen/AArch64/sve-sext-zext.ll index dc77dc838ae9f..6514ab03ae515 100644 --- a/llvm/test/CodeGen/AArch64/sve-sext-zext.ll +++ b/llvm/test/CodeGen/AArch64/sve-sext-zext.ll @@ -326,3 +326,24 @@ define @zext_b_to_d( %a) { %ext = zext %a to ret %ext } + +; Extending non power-of-two types + +define @sext_i18_i64( %a) { +; CHECK-LABEL: sext_i18_i64: +; CHECK: // %bb.0: +; CHECK-NEXT: lsl z0.d, z0.d, #46 +; CHECK-NEXT: asr z0.d, z0.d, #46 +; CHECK-NEXT: ret + %r = sext %a to + ret %r +} + +define @zext_i18_i64( %a) { +; CHECK-LABEL: zext_i18_i64: +; CHECK: // %bb.0: +; CHECK-NEXT: and z0.d, z0.d, #0x3ffff +; CHECK-NEXT: ret + %r = zext %a to + ret %r +}