; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py ; RUN: llc < %s -mtriple=riscv32 | FileCheck %s --check-prefixes=RV32 ; RUN: llc < %s -mtriple=riscv64 | FileCheck %s --check-prefixes=RV64 ; Make sure MachineCSE can combine the adds with the operands commuted. define void @commute_add_i32(i32 signext %x, i32 signext %y, i32* %p1, i32* %p2, i1 zeroext %cond) { ; RV32-LABEL: commute_add_i32: ; RV32: # %bb.0: ; RV32-NEXT: add a0, a0, a1 ; RV32-NEXT: sw a0, 0(a2) ; RV32-NEXT: beqz a4, .LBB0_2 ; RV32-NEXT: # %bb.1: # %trueblock ; RV32-NEXT: sw a0, 0(a2) ; RV32-NEXT: .LBB0_2: # %falseblock ; RV32-NEXT: ret ; ; RV64-LABEL: commute_add_i32: ; RV64: # %bb.0: ; RV64-NEXT: addw a0, a0, a1 ; RV64-NEXT: sw a0, 0(a2) ; RV64-NEXT: beqz a4, .LBB0_2 ; RV64-NEXT: # %bb.1: # %trueblock ; RV64-NEXT: sw a0, 0(a2) ; RV64-NEXT: .LBB0_2: # %falseblock ; RV64-NEXT: ret %a = add i32 %x, %y store i32 %a, i32* %p1 br i1 %cond, label %trueblock, label %falseblock trueblock: %b = add i32 %y, %x store i32 %b, i32* %p1 br label %falseblock falseblock: ret void } define void @commute_add_i64(i64 %x, i64 %y, i64* %p1, i64* %p2, i1 zeroext %cond) { ; RV32-LABEL: commute_add_i64: ; RV32: # %bb.0: ; RV32-NEXT: add a1, a1, a3 ; RV32-NEXT: add a3, a0, a2 ; RV32-NEXT: sltu a0, a3, a0 ; RV32-NEXT: add a0, a1, a0 ; RV32-NEXT: sw a3, 0(a4) ; RV32-NEXT: sw a0, 4(a4) ; RV32-NEXT: beqz a6, .LBB1_2 ; RV32-NEXT: # %bb.1: # %trueblock ; RV32-NEXT: sltu a0, a3, a2 ; RV32-NEXT: add a0, a1, a0 ; RV32-NEXT: sw a3, 0(a4) ; RV32-NEXT: sw a0, 4(a4) ; RV32-NEXT: .LBB1_2: # %falseblock ; RV32-NEXT: ret ; ; RV64-LABEL: commute_add_i64: ; RV64: # %bb.0: ; RV64-NEXT: add a0, a0, a1 ; RV64-NEXT: sd a0, 0(a2) ; RV64-NEXT: beqz a4, .LBB1_2 ; RV64-NEXT: # %bb.1: # %trueblock ; RV64-NEXT: sd a0, 0(a2) ; RV64-NEXT: .LBB1_2: # %falseblock ; RV64-NEXT: ret %a = add i64 %x, %y store i64 %a, i64* %p1 br i1 %cond, label %trueblock, label %falseblock trueblock: %b = add i64 %y, %x store i64 %b, i64* %p1 br label %falseblock falseblock: ret void }