Skip to content

[SPARC] Fix SelectForceADDRrr for global addresses and non-reg operands - #220013

Merged
brad0 merged 1 commit into
llvm:mainfrom
bvanassche:sparc
Sep 2, 2026
Merged

brad0 merged 1 commit into
llvm:mainfrom
bvanassche:sparc

Conversation

@bvanassche

Copy link
Copy Markdown
Contributor

When lowering byte-swapped memory operations on SPARC V9, LLVM emits ASI-tagged memory instructions (such as STHArr, STArr, LDArr, etc.) that require register+register addressing modes matched via ForceADDRrr.

SelectForceADDRrr previously forwarded 2-operand address nodes directly to SelectADDRrr. However, SelectADDRrr explicitly returns false when encountering SPISD::Lo (used in %hi/%lo global address calculations) or small constant offsets in order to allow standard ADDRri patterns to match. Because SelectForceADDRrr returned the result of SelectADDRrr directly instead of falling back to Base = Addr, Disp = %g0, any endian-adjusted load or store targeting a global variable failed to select and caused a backend compiler crash:
"Cannot select: SPISD::STORE_LITTLE ..."

Fix SelectForceADDRrr so that if SelectADDRrr fails to match, it falls back to evaluating the full address into a base register and using %g0 as the offset register. Also add tests for global variable byte-swapped loads and stores.

Fixes: 1ba7c96 ("[SPARC] Use hardware byteswapper when we have V9 (#191720)")

@github-actions

Copy link
Copy Markdown

Hello @bvanassche 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-sparc

Author: Bart Van Assche (bvanassche)

Changes

When lowering byte-swapped memory operations on SPARC V9, LLVM emits ASI-tagged memory instructions (such as STHArr, STArr, LDArr, etc.) that require register+register addressing modes matched via ForceADDRrr.

SelectForceADDRrr previously forwarded 2-operand address nodes directly to SelectADDRrr. However, SelectADDRrr explicitly returns false when encountering SPISD::Lo (used in %hi/%lo global address calculations) or small constant offsets in order to allow standard ADDRri patterns to match. Because SelectForceADDRrr returned the result of SelectADDRrr directly instead of falling back to Base = Addr, Disp = %g0, any endian-adjusted load or store targeting a global variable failed to select and caused a backend compiler crash:
"Cannot select: SPISD::STORE_LITTLE ..."

Fix SelectForceADDRrr so that if SelectADDRrr fails to match, it falls back to evaluating the full address into a base register and using %g0 as the offset register. Also add tests for global variable byte-swapped loads and stores.

Fixes: 1ba7c96 ("[SPARC] Use hardware byteswapper when we have V9 (#191720)")


Full diff: https://github.com/llvm/llvm-project/pull/220013.diff

2 Files Affected:

  • (modified) llvm/lib/Target/Sparc/SparcISelDAGToDAG.cpp (+2-5)
  • (modified) llvm/test/CodeGen/SPARC/bswap.ll (+201)
diff --git a/llvm/lib/Target/Sparc/SparcISelDAGToDAG.cpp b/llvm/lib/Target/Sparc/SparcISelDAGToDAG.cpp
index 8ed9c5222a3a1..bf0f53713d21f 100644
--- a/llvm/lib/Target/Sparc/SparcISelDAGToDAG.cpp
+++ b/llvm/lib/Target/Sparc/SparcISelDAGToDAG.cpp
@@ -155,11 +155,8 @@ bool SparcDAGToDAGISel::SelectADDRrr(SDValue Addr, SDValue &R1, SDValue &R2) {
 
 bool SparcDAGToDAGISel::SelectForceADDRrr(SDValue Addr, SDValue &Base,
                                           SDValue &Disp) {
-  // If it's already in R+R form then hand it over to regular ADDRrr handling.
-  if (Addr.getNumOperands() == 2 &&
-      !isa<ConstantSDNode>(Addr.getOperand(0).getNode()) &&
-      !isa<ConstantSDNode>(Addr.getOperand(1).getNode()))
-    return SelectADDRrr(Addr, Base, Disp);
+  if (SelectADDRrr(Addr, Base, Disp))
+    return true;
 
   // Otherwise we'll use the full address in base and set the offset part to
   // zero.
diff --git a/llvm/test/CodeGen/SPARC/bswap.ll b/llvm/test/CodeGen/SPARC/bswap.ll
index 5e3417617ce8e..1c8dd633e03c3 100644
--- a/llvm/test/CodeGen/SPARC/bswap.ll
+++ b/llvm/test/CodeGen/SPARC/bswap.ll
@@ -1168,4 +1168,205 @@ define void @u64tou32_bswapstore_truncated(ptr %0, i64 %1) #0 {
   ret void
 }
 
+@g16 = global i16 0, align 2
+@g32 = global i32 0, align 4
+@g64 = global i64 0, align 8
+
+define void @global_bswapstore_i16(i16 %0) #0 {
+; SPARC32-LABEL: global_bswapstore_i16:
+; SPARC32:       ! %bb.0:
+; SPARC32-NEXT:    sethi %hi(g16), %o1
+; SPARC32-NEXT:    add %o1, %lo(g16), %o1
+; SPARC32-NEXT:    retl
+; SPARC32-NEXT:    stha %o0, [%o1] #ASI_P_L
+;
+; SPARCEL-LABEL: global_bswapstore_i16:
+; SPARCEL:       ! %bb.0:
+; SPARCEL-NEXT:    sethi %hi(g16), %o1
+; SPARCEL-NEXT:    add %o1, %lo(g16), %o1
+; SPARCEL-NEXT:    retl
+; SPARCEL-NEXT:    stha %o0, [%o1] #ASI_P
+;
+; SPARC64-LABEL: global_bswapstore_i16:
+; SPARC64:       ! %bb.0:
+; SPARC64-NEXT:    sethi %h44(g16), %o1
+; SPARC64-NEXT:    add %o1, %m44(g16), %o1
+; SPARC64-NEXT:    sllx %o1, 12, %o1
+; SPARC64-NEXT:    add %o1, %l44(g16), %o1
+; SPARC64-NEXT:    retl
+; SPARC64-NEXT:    stha %o0, [%o1] #ASI_P_L
+  %2 = tail call i16 @llvm.bswap.i16(i16 %0)
+  store i16 %2, ptr @g16, align 2
+  ret void
+}
+
+define void @global_bswapstore_i32(i32 %0) #0 {
+; SPARC32-LABEL: global_bswapstore_i32:
+; SPARC32:       ! %bb.0:
+; SPARC32-NEXT:    sethi %hi(g32), %o1
+; SPARC32-NEXT:    add %o1, %lo(g32), %o1
+; SPARC32-NEXT:    retl
+; SPARC32-NEXT:    sta %o0, [%o1] #ASI_P_L
+;
+; SPARCEL-LABEL: global_bswapstore_i32:
+; SPARCEL:       ! %bb.0:
+; SPARCEL-NEXT:    sethi %hi(g32), %o1
+; SPARCEL-NEXT:    add %o1, %lo(g32), %o1
+; SPARCEL-NEXT:    retl
+; SPARCEL-NEXT:    sta %o0, [%o1] #ASI_P
+;
+; SPARC64-LABEL: global_bswapstore_i32:
+; SPARC64:       ! %bb.0:
+; SPARC64-NEXT:    sethi %h44(g32), %o1
+; SPARC64-NEXT:    add %o1, %m44(g32), %o1
+; SPARC64-NEXT:    sllx %o1, 12, %o1
+; SPARC64-NEXT:    add %o1, %l44(g32), %o1
+; SPARC64-NEXT:    retl
+; SPARC64-NEXT:    sta %o0, [%o1] #ASI_P_L
+  %2 = tail call i32 @llvm.bswap.i32(i32 %0)
+  store i32 %2, ptr @g32, align 4
+  ret void
+}
+
+define void @global_bswapstore_i64(i64 %0) #0 {
+; SPARC32-LABEL: global_bswapstore_i64:
+; SPARC32:       ! %bb.0:
+; SPARC32-NEXT:    add %sp, -104, %sp
+; SPARC32-NEXT:    add %sp, 96, %o2
+; SPARC32-NEXT:    sta %o0, [%o2] #ASI_P_L
+; SPARC32-NEXT:    add %sp, 100, %o0
+; SPARC32-NEXT:    sta %o1, [%o0] #ASI_P_L
+; SPARC32-NEXT:    ld [%sp+96], %o1
+; SPARC32-NEXT:    ld [%sp+100], %o0
+; SPARC32-NEXT:    sethi %hi(g64), %o2
+; SPARC32-NEXT:    std %o0, [%o2+%lo(g64)]
+; SPARC32-NEXT:    retl
+; SPARC32-NEXT:    add %sp, 104, %sp
+;
+; SPARCEL-LABEL: global_bswapstore_i64:
+; SPARCEL:       ! %bb.0:
+; SPARCEL-NEXT:    add %sp, -104, %sp
+; SPARCEL-NEXT:    add %sp, 96, %o2
+; SPARCEL-NEXT:    sta %o0, [%o2] #ASI_P
+; SPARCEL-NEXT:    add %sp, 100, %o0
+; SPARCEL-NEXT:    sta %o1, [%o0] #ASI_P
+; SPARCEL-NEXT:    ld [%sp+96], %o1
+; SPARCEL-NEXT:    ld [%sp+100], %o0
+; SPARCEL-NEXT:    sethi %hi(g64), %o2
+; SPARCEL-NEXT:    std %o0, [%o2+%lo(g64)]
+; SPARCEL-NEXT:    retl
+; SPARCEL-NEXT:    add %sp, 104, %sp
+;
+; SPARC64-LABEL: global_bswapstore_i64:
+; SPARC64:       ! %bb.0:
+; SPARC64-NEXT:    sethi %h44(g64), %o1
+; SPARC64-NEXT:    add %o1, %m44(g64), %o1
+; SPARC64-NEXT:    sllx %o1, 12, %o1
+; SPARC64-NEXT:    add %o1, %l44(g64), %o1
+; SPARC64-NEXT:    retl
+; SPARC64-NEXT:    stxa %o0, [%o1] #ASI_P_L
+  %2 = tail call i64 @llvm.bswap.i64(i64 %0)
+  store i64 %2, ptr @g64, align 8
+  ret void
+}
+
+define i16 @global_bswapload_i16() #0 {
+; SPARC32-LABEL: global_bswapload_i16:
+; SPARC32:       ! %bb.0:
+; SPARC32-NEXT:    sethi %hi(g16), %o0
+; SPARC32-NEXT:    add %o0, %lo(g16), %o0
+; SPARC32-NEXT:    retl
+; SPARC32-NEXT:    lduha [%o0] #ASI_P_L, %o0
+;
+; SPARCEL-LABEL: global_bswapload_i16:
+; SPARCEL:       ! %bb.0:
+; SPARCEL-NEXT:    sethi %hi(g16), %o0
+; SPARCEL-NEXT:    add %o0, %lo(g16), %o0
+; SPARCEL-NEXT:    retl
+; SPARCEL-NEXT:    lduha [%o0] #ASI_P, %o0
+;
+; SPARC64-LABEL: global_bswapload_i16:
+; SPARC64:       ! %bb.0:
+; SPARC64-NEXT:    sethi %h44(g16), %o0
+; SPARC64-NEXT:    add %o0, %m44(g16), %o0
+; SPARC64-NEXT:    sllx %o0, 12, %o0
+; SPARC64-NEXT:    add %o0, %l44(g16), %o0
+; SPARC64-NEXT:    retl
+; SPARC64-NEXT:    lduha [%o0] #ASI_P_L, %o0
+  %1 = load i16, ptr @g16, align 2
+  %2 = tail call i16 @llvm.bswap.i16(i16 %1)
+  ret i16 %2
+}
+
+define i32 @global_bswapload_i32() #0 {
+; SPARC32-LABEL: global_bswapload_i32:
+; SPARC32:       ! %bb.0:
+; SPARC32-NEXT:    sethi %hi(g32), %o0
+; SPARC32-NEXT:    add %o0, %lo(g32), %o0
+; SPARC32-NEXT:    retl
+; SPARC32-NEXT:    lda [%o0] #ASI_P_L, %o0
+;
+; SPARCEL-LABEL: global_bswapload_i32:
+; SPARCEL:       ! %bb.0:
+; SPARCEL-NEXT:    sethi %hi(g32), %o0
+; SPARCEL-NEXT:    add %o0, %lo(g32), %o0
+; SPARCEL-NEXT:    retl
+; SPARCEL-NEXT:    lda [%o0] #ASI_P, %o0
+;
+; SPARC64-LABEL: global_bswapload_i32:
+; SPARC64:       ! %bb.0:
+; SPARC64-NEXT:    sethi %h44(g32), %o0
+; SPARC64-NEXT:    add %o0, %m44(g32), %o0
+; SPARC64-NEXT:    sllx %o0, 12, %o0
+; SPARC64-NEXT:    add %o0, %l44(g32), %o0
+; SPARC64-NEXT:    retl
+; SPARC64-NEXT:    lda [%o0] #ASI_P_L, %o0
+  %1 = load i32, ptr @g32, align 4
+  %2 = tail call i32 @llvm.bswap.i32(i32 %1)
+  ret i32 %2
+}
+
+define i64 @global_bswapload_i64() #0 {
+; SPARC32-LABEL: global_bswapload_i64:
+; SPARC32:       ! %bb.0:
+; SPARC32-NEXT:    add %sp, -104, %sp
+; SPARC32-NEXT:    sethi %hi(g64), %o0
+; SPARC32-NEXT:    ldd [%o0+%lo(g64)], %o0
+; SPARC32-NEXT:    add %sp, 96, %o2
+; SPARC32-NEXT:    sta %o1, [%o2] #ASI_P_L
+; SPARC32-NEXT:    add %sp, 100, %o2
+; SPARC32-NEXT:    sta %o0, [%o2] #ASI_P_L
+; SPARC32-NEXT:    ld [%sp+96], %o0
+; SPARC32-NEXT:    ld [%sp+100], %o1
+; SPARC32-NEXT:    retl
+; SPARC32-NEXT:    add %sp, 104, %sp
+;
+; SPARCEL-LABEL: global_bswapload_i64:
+; SPARCEL:       ! %bb.0:
+; SPARCEL-NEXT:    add %sp, -104, %sp
+; SPARCEL-NEXT:    sethi %hi(g64), %o0
+; SPARCEL-NEXT:    ldd [%o0+%lo(g64)], %o0
+; SPARCEL-NEXT:    add %sp, 96, %o2
+; SPARCEL-NEXT:    sta %o1, [%o2] #ASI_P
+; SPARCEL-NEXT:    add %sp, 100, %o2
+; SPARCEL-NEXT:    sta %o0, [%o2] #ASI_P
+; SPARCEL-NEXT:    ld [%sp+96], %o0
+; SPARCEL-NEXT:    ld [%sp+100], %o1
+; SPARCEL-NEXT:    retl
+; SPARCEL-NEXT:    add %sp, 104, %sp
+;
+; SPARC64-LABEL: global_bswapload_i64:
+; SPARC64:       ! %bb.0:
+; SPARC64-NEXT:    sethi %h44(g64), %o0
+; SPARC64-NEXT:    add %o0, %m44(g64), %o0
+; SPARC64-NEXT:    sllx %o0, 12, %o0
+; SPARC64-NEXT:    add %o0, %l44(g64), %o0
+; SPARC64-NEXT:    retl
+; SPARC64-NEXT:    ldxa [%o0] #ASI_P_L, %o0
+  %1 = load i64, ptr @g64, align 8
+  %2 = tail call i64 @llvm.bswap.i64(i64 %1)
+  ret i64 %2
+}
+
 attributes #0 = { nounwind }
+

When lowering byte-swapped memory operations on SPARC V9, LLVM emits
ASI-tagged memory instructions (such as STHArr, STArr, LDArr, etc.)
that require register+register addressing modes matched via ForceADDRrr.

SelectForceADDRrr previously forwarded 2-operand address nodes directly
to SelectADDRrr. However, SelectADDRrr explicitly returns false when
encountering SPISD::Lo (used in %hi/%lo global address calculations) or
small constant offsets in order to allow standard ADDRri patterns to
match. Because SelectForceADDRrr returned the result of SelectADDRrr
directly instead of falling back to Base = Addr, Disp = %g0, any
endian-adjusted load or store targeting a global variable failed to
select and caused a backend compiler crash:
  "Cannot select: SPISD::STORE_LITTLE ..."

Fix SelectForceADDRrr so that if SelectADDRrr fails to match, it falls
back to evaluating the full address into a base register and using %g0
as the offset register. Also add tests for global variable byte-swapped
loads and stores.

Fixes: 1ba7c96 ("[SPARC] Use hardware byteswapper when we have V9 (llvm#191720)")
Assisted-by: Gemini
Signed-off-by: Bart Van Assche <[email protected]>
@bvanassche

Copy link
Copy Markdown
Contributor Author

I have read and followed the LLVM AI Tool Use Policy.

@brad0

brad0 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

cc @koachan @s-barannikov

@brad0
brad0 merged commit d378144 into llvm:main Sep 2, 2026
12 checks passed
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

@bvanassche Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci

llvm-ci commented Sep 2, 2026

Copy link
Copy Markdown

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/49067

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: Analysis/ftime-trace.cpp' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/lib/clang/24/include -nostdsysteminc -analyze -setup-static-analyzer -analyzer-checker=core /Users/buildbot/buildbot-root/llvm-project/clang/test/Analysis/ftime-trace.cpp -ftime-trace=/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/tools/clang/test/Analysis/Output/ftime-trace.cpp.tmp.raw.json -ftime-trace-granularity=0 -verify
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/lib/clang/24/include -nostdsysteminc -analyze -setup-static-analyzer -analyzer-checker=core /Users/buildbot/buildbot-root/llvm-project/clang/test/Analysis/ftime-trace.cpp -ftime-trace=/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/tools/clang/test/Analysis/Output/ftime-trace.cpp.tmp.raw.json -ftime-trace-granularity=0 -verify
# note: command had no output on stdout or stderr
# RUN: at line 2
"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9" -c 'import json, sys; print(json.dumps(json.load(sys.stdin), indent=4))' < /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/tools/clang/test/Analysis/Output/ftime-trace.cpp.tmp.raw.json > /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/tools/clang/test/Analysis/Output/ftime-trace.cpp.tmp.formatted.json
# executed command: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9 -c 'import json, sys; print(json.dumps(json.load(sys.stdin), indent=4))'
# note: command had no output on stdout or stderr
# RUN: at line 3
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck --input-file=/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/tools/clang/test/Analysis/Output/ftime-trace.cpp.tmp.formatted.json --check-prefix=CHECK /Users/buildbot/buildbot-root/llvm-project/clang/test/Analysis/ftime-trace.cpp
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck --input-file=/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/tools/clang/test/Analysis/Output/ftime-trace.cpp.tmp.formatted.json --check-prefix=CHECK /Users/buildbot/buildbot-root/llvm-project/clang/test/Analysis/ftime-trace.cpp
# .---command stderr------------
# | �[1m/Users/buildbot/buildbot-root/llvm-project/clang/test/Analysis/ftime-trace.cpp:34:11: �[0m�[0;1;31merror: �[0m�[1mCHECK: expected string not found in input
�[0m# | �[1m�[0m// CHECK: "name": "Total CheckerManager::runCheckersForStmt (Pre)",
# | �[0;1;32m          ^
�[0m# | �[0;1;32m�[0m�[1m/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/tools/clang/test/Analysis/Output/ftime-trace.cpp.tmp.formatted.json:2630:3: �[0m�[0;1;30mnote: �[0m�[1mscanning from here
�[0m# | �[1m�[0m }
# | �[0;1;32m  ^
�[0m# | �[0;1;32m�[0m�[1m/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/tools/clang/test/Analysis/Output/ftime-trace.cpp.tmp.formatted.json:2818:2: �[0m�[0;1;30mnote: �[0m�[1mpossible intended match here
�[0m# | �[1m�[0m "name": "Total CheckerManager::runCheckersForStmt (Post)",
# | �[0;1;32m ^
�[0m# | �[0;1;32m�[0m
# | Input file: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/tools/clang/test/Analysis/Output/ftime-trace.cpp.tmp.formatted.json
# | Check file: /Users/buildbot/buildbot-root/llvm-project/clang/test/Analysis/ftime-trace.cpp
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# | �[1m�[0m�[0;1;90m            1: �[0m�[1m�[0;1;46m{ �[0m
# | �[0;1;90m            2: �[0m�[1m�[0;1;46m "traceEvents": [ �[0m
# | �[0;1;90m            3: �[0m�[1m�[0;1;46m { �[0m
# | �[0;1;90m            4: �[0m�[1m�[0;1;46m "pid": 66218, �[0m
# | �[0;1;90m            5: �[0m�[1m�[0;1;46m "tid": 259, �[0m
# | �[0;1;90m            6: �[0m�[1m�[0;1;46m "ts": 3668, �[0m
# | �[0;1;90m            7: �[0m�[1m�[0;1;46m "ph": "X", �[0m
# | �[0;1;90m            8: �[0m�[1m�[0;1;46m "dur": 229, �[0m
# | �[0;1;90m            9: �[0m�[1m�[0;1;46m "name": "ParseDeclarationOrFunctionDefinition", �[0m
# | �[0;1;90m           10: �[0m�[1m�[0;1;46m "args": { �[0m
# | �[0;1;90m           11: �[0m�[1m�[0;1;46m "detail": "/Users/buildbot/buildbot-root/llvm-project/clang/test/Analysis/ftime-trace.cpp:48:1" �[0m
# | �[0;1;90m           12: �[0m�[1m�[0;1;46m } �[0m
# | �[0;1;90m           13: �[0m�[1m�[0;1;46m }, �[0m
# | �[0;1;90m           14: �[0m�[1m�[0;1;46m { �[0m
# | �[0;1;90m           15: �[0m�[1m�[0;1;46m "pid": 66218, �[0m
# | �[0;1;90m           16: �[0m�[1m�[0;1;46m "tid": 259, �[0m
...

Iasonaskrpr pushed a commit to Iasonaskrpr/llvm-project that referenced this pull request Sep 4, 2026
…ds (llvm#220013)

When lowering byte-swapped memory operations on SPARC V9, LLVM emits
ASI-tagged memory instructions (such as STHArr, STArr, LDArr, etc.) that
require register+register addressing modes matched via ForceADDRrr.

SelectForceADDRrr previously forwarded 2-operand address nodes directly
to SelectADDRrr. However, SelectADDRrr explicitly returns false when
encountering SPISD::Lo (used in %hi/%lo global address calculations) or
small constant offsets in order to allow standard ADDRri patterns to
match. Because SelectForceADDRrr returned the result of SelectADDRrr
directly instead of falling back to Base = Addr, Disp = %g0, any
endian-adjusted load or store targeting a global variable failed to
select and caused a backend compiler crash:
  "Cannot select: SPISD::STORE_LITTLE ..."

Fix SelectForceADDRrr so that if SelectADDRrr fails to match, it falls
back to evaluating the full address into a base register and using %g0
as the offset register. Also add tests for global variable byte-swapped
loads and stores.

Fixes: 1ba7c96 ("[SPARC] Use hardware byteswapper when we have V9
(llvm#191720)")

Signed-off-by: Bart Van Assche <[email protected]>
asudarsa-qti pushed a commit to asudarsa-qti/llvm-project that referenced this pull request Sep 4, 2026
…ds (llvm#220013)

When lowering byte-swapped memory operations on SPARC V9, LLVM emits
ASI-tagged memory instructions (such as STHArr, STArr, LDArr, etc.) that
require register+register addressing modes matched via ForceADDRrr.

SelectForceADDRrr previously forwarded 2-operand address nodes directly
to SelectADDRrr. However, SelectADDRrr explicitly returns false when
encountering SPISD::Lo (used in %hi/%lo global address calculations) or
small constant offsets in order to allow standard ADDRri patterns to
match. Because SelectForceADDRrr returned the result of SelectADDRrr
directly instead of falling back to Base = Addr, Disp = %g0, any
endian-adjusted load or store targeting a global variable failed to
select and caused a backend compiler crash:
  "Cannot select: SPISD::STORE_LITTLE ..."

Fix SelectForceADDRrr so that if SelectADDRrr fails to match, it falls
back to evaluating the full address into a base register and using %g0
as the offset register. Also add tests for global variable byte-swapped
loads and stores.

Fixes: 1ba7c96 ("[SPARC] Use hardware byteswapper when we have V9
(llvm#191720)")

Signed-off-by: Bart Van Assche <[email protected]>
addmisol pushed a commit to addmisol/llvm-project2 that referenced this pull request Sep 6, 2026
…ds (llvm#220013)

When lowering byte-swapped memory operations on SPARC V9, LLVM emits
ASI-tagged memory instructions (such as STHArr, STArr, LDArr, etc.) that
require register+register addressing modes matched via ForceADDRrr.

SelectForceADDRrr previously forwarded 2-operand address nodes directly
to SelectADDRrr. However, SelectADDRrr explicitly returns false when
encountering SPISD::Lo (used in %hi/%lo global address calculations) or
small constant offsets in order to allow standard ADDRri patterns to
match. Because SelectForceADDRrr returned the result of SelectADDRrr
directly instead of falling back to Base = Addr, Disp = %g0, any
endian-adjusted load or store targeting a global variable failed to
select and caused a backend compiler crash:
  "Cannot select: SPISD::STORE_LITTLE ..."

Fix SelectForceADDRrr so that if SelectADDRrr fails to match, it falls
back to evaluating the full address into a base register and using %g0
as the offset register. Also add tests for global variable byte-swapped
loads and stores.

Fixes: 1ba7c96 ("[SPARC] Use hardware byteswapper when we have V9
(llvm#191720)")

Signed-off-by: Bart Van Assche <[email protected]>
dyung pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 16, 2026
…ds (llvm#220013)

When lowering byte-swapped memory operations on SPARC V9, LLVM emits
ASI-tagged memory instructions (such as STHArr, STArr, LDArr, etc.) that
require register+register addressing modes matched via ForceADDRrr.

SelectForceADDRrr previously forwarded 2-operand address nodes directly
to SelectADDRrr. However, SelectADDRrr explicitly returns false when
encountering SPISD::Lo (used in %hi/%lo global address calculations) or
small constant offsets in order to allow standard ADDRri patterns to
match. Because SelectForceADDRrr returned the result of SelectADDRrr
directly instead of falling back to Base = Addr, Disp = %g0, any
endian-adjusted load or store targeting a global variable failed to
select and caused a backend compiler crash:
  "Cannot select: SPISD::STORE_LITTLE ..."

Fix SelectForceADDRrr so that if SelectADDRrr fails to match, it falls
back to evaluating the full address into a base register and using %g0
as the offset register. Also add tests for global variable byte-swapped
loads and stores.

Fixes: 1ba7c96 ("[SPARC] Use hardware byteswapper when we have V9
(llvm#191720)")

Signed-off-by: Bart Van Assche <[email protected]>
(cherry picked from commit d378144)
@bvanassche
bvanassche deleted the sparc branch November 19, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants