Index: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64InstrInfo.cpp +++ llvm/lib/Target/AArch64/AArch64InstrInfo.cpp @@ -5029,6 +5029,18 @@ case AArch64::ORRv16i8: case AArch64::EORv8i8: case AArch64::EORv16i8: + // -- SVE instructions -- + case AArch64::ADD_ZZZ_B: + case AArch64::ADD_ZZZ_H: + case AArch64::ADD_ZZZ_S: + case AArch64::ADD_ZZZ_D: + case AArch64::MUL_ZZZ_B: + case AArch64::MUL_ZZZ_H: + case AArch64::MUL_ZZZ_S: + case AArch64::MUL_ZZZ_D: + case AArch64::AND_ZZZ: + case AArch64::ORR_ZZZ: + case AArch64::EOR_ZZZ: return true; default: Index: llvm/test/CodeGen/AArch64/machine-combiner.ll =================================================================== --- llvm/test/CodeGen/AArch64/machine-combiner.ll +++ llvm/test/CodeGen/AArch64/machine-combiner.ll @@ -643,6 +643,62 @@ ret %t2 } +; Verify that scalable vector integer arithmetic operations are reassociated. + +define @reassociate_muls_nxv4i32( %x0, %x1, %x2, %x3) { +; CHECK-LABEL: reassociate_muls_nxv4i32: +; CHECK: // %bb.0: +; CHECK-NEXT: mul z0.s, z0.s, z1.s +; CHECK-NEXT: mul z1.s, z3.s, z2.s +; CHECK-NEXT: mul z0.s, z1.s, z0.s +; CHECK-NEXT: ret + %t0 = mul %x0, %x1 + %t1 = mul %x2, %t0 + %t2 = mul %x3, %t1 + ret %t2 +} + +define @reassociate_adds_nxv2i64( %x0, %x1, %x2, %x3) { +; CHECK-LABEL: reassociate_adds_nxv2i64: +; CHECK: // %bb.0: +; CHECK-NEXT: add z0.d, z0.d, z1.d +; CHECK-NEXT: add z1.d, z3.d, z2.d +; CHECK-NEXT: add z0.d, z1.d, z0.d +; CHECK-NEXT: ret + %t0 = add %x0, %x1 + %t1 = add %x2, %t0 + %t2 = add %x3, %t1 + ret %t2 +} + +; Verify that scalable vector bitwise operations are reassociated. + +define @reassociate_ands_nxv16i8( %x0, %x1, %x2, %x3) { +; CHECK-LABEL: reassociate_ands_nxv16i8: +; CHECK: // %bb.0: +; CHECK-NEXT: orr z0.d, z0.d, z1.d +; CHECK-NEXT: and z1.d, z2.d, z3.d +; CHECK-NEXT: and z0.d, z0.d, z1.d +; CHECK-NEXT: ret + %t0 = or %x0, %x1 + %t1 = and %t0, %x2 + %t2 = and %t1, %x3 + ret %t2 +} + +define @reassociate_ors_nxv8i16( %x0, %x1, %x2, %x3) { +; CHECK-LABEL: reassociate_ors_nxv8i16: +; CHECK: // %bb.0: +; CHECK-NEXT: eor z0.d, z0.d, z1.d +; CHECK-NEXT: orr z1.d, z2.d, z3.d +; CHECK-NEXT: orr z0.d, z0.d, z1.d +; CHECK-NEXT: ret + %t0 = xor %x0, %x1 + %t1 = or %t0, %x2 + %t2 = or %t1, %x3 + ret %t2 +} + ; PR25016: https://llvm.org/bugs/show_bug.cgi?id=25016 ; Verify that reassociation is not happening needlessly or wrongly.