|
| 1 | +; RUN: opt -load-pass-plugin %llvmshlibdir/ReplacerPass_ShulpinIlya_FIIT1_LLVM_IR%pluginext \ |
| 2 | +; RUN: -passes="ReplacerPass" -S %s | FileCheck %s |
| 3 | + |
| 4 | +;===------------------------------------------------------------------------===; |
| 5 | +; Test 1: @add - Reference implementation of add function (should not change) |
| 6 | +; Checks that function @add itself is not transformed by the pass |
| 7 | +;===------------------------------------------------------------------------===; |
| 8 | + |
| 9 | +; CHECK: define i32 @add(i32 %a, i32 %b) |
| 10 | +; CHECK: %result = add i32 %a, %b |
| 11 | +; CHECK: ret i32 %result |
| 12 | +; CHECK-NOT: add i32 |
| 13 | + |
| 14 | +define i32 @add(i32 %a, i32 %b) { |
| 15 | + %result = add i32 %a, %b |
| 16 | + ret i32 %result |
| 17 | +} |
| 18 | + |
| 19 | +;===------------------------------------------------------------------------===; |
| 20 | +; Test 2: @foo - Matching types, call to @add should replace the add instruction |
| 21 | +; This should be transformed to a call to @add because the operand types match |
| 22 | +;===------------------------------------------------------------------------===; |
| 23 | + |
| 24 | +; CHECK-LABEL: define i32 @foo(i32 %x, i32 %y) |
| 25 | +; CHECK-NEXT: call i32 @add(i32 %x, i32 %y) |
| 26 | +; CHECK-NEXT: ret i32 %sum |
| 27 | +; CHECK-NOT: add i32 |
| 28 | + |
| 29 | +define i32 @foo(i32 %x, i32 %y) { |
| 30 | + %sum = add i32 %x, %y |
| 31 | + ret i32 %sum |
| 32 | +} |
| 33 | + |
| 34 | + |
| 35 | +;===------------------------------------------------------------------------===; |
| 36 | +; Test 3: @bar - Same as @foo, another usage of i32 add replaced with @add |
| 37 | +; Verifies that the pass replaces all i32 add instructions consistently |
| 38 | +;===------------------------------------------------------------------------===; |
| 39 | + |
| 40 | +; CHECK-LABEL: define i32 @bar(i32 %m, i32 %n) |
| 41 | +; CHECK-NEXT: %sum1 = call i32 @add(i32 %m, i32 %n) |
| 42 | +; CHECK-NEXT: ret i32 %sum |
| 43 | +; CHECK-NOT: call i32 @add |
| 44 | + |
| 45 | +define i32 @bar(i32 %m, i32 %n) { |
| 46 | + %sum = add i32 %m, %n |
| 47 | + ret i32 %sum |
| 48 | +} |
| 49 | + |
| 50 | +;===------------------------------------------------------------------------===; |
| 51 | +; Test 4: @goo - i64 add should not be replaced, because @add only accepts i32 |
| 52 | +; Ensures type mismatch prevents transformation |
| 53 | +;===------------------------------------------------------------------------===; |
| 54 | + |
| 55 | +; CHECK-LABEL: define i64 @goo(i64 %x, i64 %y) |
| 56 | +; CHECK-NEXT: %sum = add i64 %x, %y |
| 57 | +; CHECK-NEXT: ret i64 %sum |
| 58 | + |
| 59 | +define i64 @goo(i64 %x, i64 %y) { |
| 60 | + %sum = add i64 %x, %y |
| 61 | + ret i64 %sum |
| 62 | +} |
| 63 | + |
| 64 | +;===------------------------------------------------------------------------===; |
| 65 | +; Test 5: @foo_alt - No add instruction here, should remain unchanged |
| 66 | +; Also checks that unrelated functions are not transformed |
| 67 | +;===------------------------------------------------------------------------===; |
| 68 | + |
| 69 | + |
| 70 | +; CHECK-NOT: define i64 @add( |
| 71 | +; CHECK-LABEL: define i64 @foo_alt(i64 %x) |
| 72 | + |
| 73 | +define i64 @foo_alt(i64 %x) { |
| 74 | + ret i64 %x |
| 75 | +} |
| 76 | + |
| 77 | +;===------------------------------------------------------------------------===; |
| 78 | +; Test 6: @baz - add of mismatched type (i1), should not be replaced |
| 79 | +; Verifies the pass skips non-i32 instructions (e.g. bitwise bools) |
| 80 | +;===------------------------------------------------------------------------===; |
| 81 | + |
| 82 | +; CHECK-LABEL: define i1 @baz(i1 %a, i1 %b) |
| 83 | +; CHECK: %r = add i1 %a, %b |
| 84 | +; CHECK-NOT: call i32 @add |
| 85 | + |
| 86 | +define i1 @baz(i1 %a, i1 %b) { |
| 87 | + %r = add i1 %a, %b |
| 88 | + ret i1 %r |
| 89 | +} |
| 90 | + |
| 91 | +;===------------------------------------------------------------------------===; |
| 92 | +; Test 7: @multiple_adds - Only i32 adds should be replaced, others kept |
| 93 | +; This mixes types to ensure partial transformation |
| 94 | +;===------------------------------------------------------------------------===; |
| 95 | + |
| 96 | +; CHECK-LABEL: define void @multiple_adds(i32 %a, i32 %b, i64 %x, i64 %y) |
| 97 | +; CHECK: call i32 @add(i32 %a, i32 %b) |
| 98 | +; CHECK: %b2 = add i64 %x, %y |
| 99 | + |
| 100 | +define void @multiple_adds(i32 %a, i32 %b, i64 %x, i64 %y) { |
| 101 | + %b1 = add i32 %a, %b |
| 102 | + %b2 = add i64 %x, %y |
| 103 | + call void @use(i32 %b1, i64 %b2) |
| 104 | + ret void |
| 105 | +} |
| 106 | + |
| 107 | +declare void @use(i32, i64) |
0 commit comments