Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang2] Full support for opaque pointers #1322

Merged

Conversation

xinliu-hnc
Copy link
Collaborator

This PR depends on PR #1321, rebase this branch after merging PR #1321 into the master branch.

This PR removes the redundant bitcast instructions generated by functions as well as the redundant bitcast instructions in some hard-coded strings, and for some hard-coded typed pointers in code blocks controlled by conditional compilation macros, we rewrite them. We also modify some test cases that use redundant bitcast instructions.

@bryanpkc
Copy link
Collaborator

@xinliu-hnc Please rebase the branch.

@xinliu-hnc
Copy link
Collaborator Author

@xinliu-hnc Please rebase the branch.

Rebased.

rewrite typed pointer with 'ptr'.

1. In the function 'make_bitcast()', a copy of the source with the type of
   the dest is returned when both the data types of source and dest are LL_PTR.
2. Due to the above modification, in function 'make_load()', flang should
   always get the load type from ll_type in the operand.
3. Remove the bitcast instruction used to store different types of results to
   the address of the return variable when processing ENTRY statements.
4. For some hard-coded typed pointers in code blocks controlled by conditional
   compilation macros, rewrite them with 'ptr'.
Copy link
Collaborator

@bryanpkc bryanpkc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@bryanpkc
Copy link
Collaborator

@xinliu-hnc Are any additional changes required? Have you tested the opaque pointer support on workloads outside of the Classic Flang regression tests?

@xinliu-hnc
Copy link
Collaborator Author

@xinliu-hnc Are any additional changes required? Have you tested the opaque pointer support on workloads outside of the Classic Flang regression tests?

I don't have any additional changes. I've tested NPB 3.4, SPEC CPU 2017 and SPEC OMP 2012, and there is no regression found.

@bryanpkc
Copy link
Collaborator

I compiled a simple test case:

function cdexp (in1)
  complex(kind=8) :: in1, cdexp
  cdexp = exp(in1)
end function cdexp

This emits the following IR:

define void @cdexp_(ptr %cdexp, ptr %in1) !dbg !15 {
L.entry:
    %.ka0000_338 = alloca <{double, double}>, align 16

    br label %L.LB1_336
L.LB1_336:
    %0 = bitcast ptr %.ka0000_338 to ptr, !dbg !18
    %1 = bitcast ptr %in1 to ptr, !dbg !18
    %2 = load <{double, double}>, ptr %1, align 1, !dbg !18
    %3 = extractvalue <{double, double}> %2, 0, !dbg !18
    %4 = bitcast ptr %in1 to ptr, !dbg !18
    %5 = load <{double, double}>, ptr %4, align 1, !dbg !18
    %6 = extractvalue <{double, double}> %5, 1, !dbg !18
    %7 = bitcast ptr @__mth_i_cdexp to ptr, !dbg !18
    %8 = call i32 (ptr, double, double, ...) %7 (ptr %0, double %3, double %6), !dbg !18
    %9 = load <{double, double}>, ptr %.ka0000_338, align 1, !dbg !18
    %10 = bitcast ptr %cdexp to ptr, !dbg !18
    store <{double, double}> %9, ptr %10, align 8, !dbg !18
    ret void, !dbg !19
}

As you can see, there is a lot of unnecessary bitcast instructions. Could you submit a follow-up PR to remove them?

@bryanpkc bryanpkc changed the title [feature][flang2] Full support for opaque pointers [flang2] Full support for opaque pointers Dec 17, 2022
@bryanpkc
Copy link
Collaborator

As you can see, there is a lot of unnecessary bitcast instructions. Could you submit a follow-up PR to remove them?

Apologies, this was a mistake on our part. The bitcast instructions are not seen after cherry-picking this PR correctly.

@bryanpkc
Copy link
Collaborator

I think we have sufficient approvals to merge this.

@bryanpkc bryanpkc merged commit 2d211cf into flang-compiler:master Dec 19, 2022
@inclyc
Copy link

inclyc commented Jul 23, 2024

Hi @bryanpkc @shivaramaarao,

Could you please double check why the alignment of load instructions in generated IR ? Let's see the example above:

%.ka0000_338 = alloca <{double, double}>, align 16

%.ka0000_338 is allocated on stack and has alignment = 16

%9 = load <{double, double}>, ptr %.ka0000_338, align 1, !dbg !18

Why this pointer is loaded with align 1 ? This will leads to bad code generation in backends I suppose? Would you mind give me some advice where is the alignment generated?

@pawosm-arm
Copy link
Collaborator

Hi @inclyc, could you type-in some minimal reproducer for the observed problem?

@inclyc
Copy link

inclyc commented Jul 23, 2024

Hi @inclyc, could you type-in some minimal reproducer for the observed problem?

Hi @pawosm-arm , thanks for your quick reply! Just see the example above: #1322 (comment)

@bryanpkc
Copy link
Collaborator

LLVM IR verifier will add align 1 even if the frontend omits the alignment. The problem is that flang2 fails to compute the correct type size for loads of complex types. I will submit a PR to fix the bug.

@bryanpkc
Copy link
Collaborator

#1449 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants