1; RUN: opt < %s -slsr -nary-reassociate -S | FileCheck %s 2; RUN: opt < %s -slsr -S | opt -passes='nary-reassociate' -S | FileCheck %s 3; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s --check-prefix=PTX 4 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.u32 [[b:%r[0-9]+]], [nary_reassociate_after_slsr_param_1]; 21 %ab = add i32 %a, %b 22 %abc = add i32 %ab, %c 23 call void @foo(i32 %abc) 24; CHECK: call void @foo(i32 %abc) 25; PTX: st.param.b32 [param0+0], [[abc:%r[0-9]+]]; 26 27 %b2 = shl i32 %b, 1 28 %ab2 = add i32 %a, %b2 29 %ab2c = add i32 %ab2, %c 30; CHECK-NEXT: %ab2c = add i32 %abc, %b 31; 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+0], [[ab2c]]; 35 36 %b3 = mul i32 %b, 3 37 %ab3 = add i32 %a, %b3 38 %ab3c = add i32 %ab3, %c 39; CHECK-NEXT: %ab3c = add i32 %ab2c, %b 40; 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+0], [[ab3c]]; 44 45 ret void 46} 47 48declare void @foo(i32) 49