Index: lib/Target/SystemZ/SystemZISelLowering.cpp =================================================================== --- lib/Target/SystemZ/SystemZISelLowering.cpp +++ lib/Target/SystemZ/SystemZISelLowering.cpp @@ -5537,8 +5537,9 @@ // entirely, but we can still truncate it to a 16-bit value. This prevents // us from ending up with a NILL with a signed operand, which will cause the // instruction printer to abort. + EVT VT = N->getValueType(0); SDValue N1 = N->getOperand(1); - if (N1.getOpcode() == ISD::AND) { + if (N1.getOpcode() == ISD::AND && VT.getScalarSizeInBits() <= 64) { SDValue AndMaskOp = N1->getOperand(1); auto *AndMask = dyn_cast(AndMaskOp); Index: test/CodeGen/SystemZ/shift-12.ll =================================================================== --- test/CodeGen/SystemZ/shift-12.ll +++ test/CodeGen/SystemZ/shift-12.ll @@ -104,3 +104,14 @@ %reuse = add i32 %and, %shift ret i32 %reuse } + +; Test that AND is not removed for i128 (which calls __ashlti3) +define i128 @f11(i128 %a, i32 %sh) { +; CHECK-LABEL: f11: +; CHECK: risbg %r4, %r4, 57, 191, 0 +; CHECK: brasl %r14, __ashlti3@PLT + %and = and i32 %sh, 127 + %ext = zext i32 %and to i128 + %shift = shl i128 %a, %ext + ret i128 %shift +}