Index: llvm/include/llvm/Target/GlobalISel/Combine.td =================================================================== --- llvm/include/llvm/Target/GlobalISel/Combine.td +++ llvm/include/llvm/Target/GlobalISel/Combine.td @@ -211,7 +211,7 @@ // Fold (0 op x) - > 0 def binop_left_to_zero: GICombineRule< (defs root:$root), - (match (wip_match_opcode G_SDIV, G_UDIV, G_SREM, G_UREM):$root, + (match (wip_match_opcode G_SDIV, G_UDIV, G_SREM, G_UREM, G_MUL):$root, [{ return Helper.matchOperandIsZero(*${root}, 1); }]), (apply [{ return Helper.replaceSingleDefInstWithOperand(*${root}, 1); }]) >; Index: llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir =================================================================== --- llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir +++ llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir @@ -41,14 +41,14 @@ ... --- -name: mul_0 +name: mul_0_rhs tracksRegLiveness: true body: | bb.1.entry: liveins: $w0 ; Fold (x * 0) -> 0 ; - ; CHECK-LABEL: name: mul_0 + ; CHECK-LABEL: name: mul_0_rhs ; CHECK: liveins: $w0 ; CHECK: %cst:_(s32) = G_CONSTANT i32 0 ; CHECK: $w0 = COPY %cst(s32) @@ -59,6 +59,26 @@ $w0 = COPY %op(s32) RET_ReallyLR implicit $w0 +... +--- +name: mul_0_lhs +tracksRegLiveness: true +body: | + bb.1.entry: + liveins: $w0 + ; Fold (0 * x) -> 0 + ; + ; CHECK-LABEL: name: mul_0_lhs + ; CHECK: liveins: $w0 + ; CHECK: %cst:_(s32) = G_CONSTANT i32 0 + ; CHECK: $w0 = COPY %cst(s32) + ; CHECK: RET_ReallyLR implicit $w0 + %x:_(s32) = COPY $w0 + %cst:_(s32) = G_CONSTANT i32 0 + %op:_(s32) = G_MUL %cst(s32), %x + $w0 = COPY %op(s32) + RET_ReallyLR implicit $w0 + ... # FIXME: Probably should be able to replace this.