49 lines · plain
1; RUN: opt < %s -passes=slsr,nary-reassociate -S | FileCheck %s2; RUN: opt < %s -passes=slsr -S | opt -passes='nary-reassociate' -S | FileCheck %s3; RUN: llc < %s -mtriple=nvptx64 -mcpu=sm_20 | FileCheck %s --check-prefix=PTX4 5target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"6 7; foo((a + b) + c);8; foo((a + b * 2) + c);9; foo((a + b * 3) + c);10; =>11; abc = (a + b) + c;12; foo(abc);13; ab2c = abc + b;14; foo(ab2c);15; ab3c = ab2c + b;16; foo(ab3c);17define void @nary_reassociate_after_slsr(i32 %a, i32 %b, i32 %c) {18; CHECK-LABEL: @nary_reassociate_after_slsr(19; PTX-LABEL: .visible .func nary_reassociate_after_slsr(20; PTX: ld.param.b32 [[b:%r[0-9]+]], [nary_reassociate_after_slsr_param_1];21 %ab = add i32 %a, %b22 %abc = add i32 %ab, %c23 call void @foo(i32 %abc)24; CHECK: call void @foo(i32 %abc)25; PTX: st.param.b32 [param0], [[abc:%r[0-9]+]];26 27 %b2 = shl i32 %b, 128 %ab2 = add i32 %a, %b229 %ab2c = add i32 %ab2, %c30; CHECK-NEXT: %ab2c = add i32 %abc, %b31; PTX: add.s32 [[ab2c:%r[0-9]+]], [[abc]], [[b]]32 call void @foo(i32 %ab2c)33; CHECK-NEXT: call void @foo(i32 %ab2c)34; PTX: st.param.b32 [param0], [[ab2c]];35 36 %b3 = mul i32 %b, 337 %ab3 = add i32 %a, %b338 %ab3c = add i32 %ab3, %c39; CHECK-NEXT: %ab3c = add i32 %ab2c, %b40; PTX: add.s32 [[ab3c:%r[0-9]+]], [[ab2c]], [[b]]41 call void @foo(i32 %ab3c)42; CHECK-NEXT: call void @foo(i32 %ab3c)43; PTX: st.param.b32 [param0], [[ab3c]];44 45 ret void46}47 48declare void @foo(i32)49