[llvm] 19311e0 - [PowerPC] Do not convert lwz to lwa if the offset is not a multiple of 4

Nemanja Ivanovic via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 31 07:54:36 PST 2023


Author: Nemanja Ivanovic
Date: 2023-01-31T09:54:29-06:00
New Revision: 19311e0a2e70c3775a67efe55780af65eb484b41

URL: https://github.com/llvm/llvm-project/commit/19311e0a2e70c3775a67efe55780af65eb484b41
DIFF: https://github.com/llvm/llvm-project/commit/19311e0a2e70c3775a67efe55780af65eb484b41.diff

LOG: [PowerPC] Do not convert lwz to lwa if the offset is not a multiple of 4

The transform that converts this checks the alignment of the global
object being accessed. However, there was no check for the offset
within the global object which caused the compiler to produce a
DS relocation for an unaligned address.

Added: 
    

Modified: 
    llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
    llvm/test/CodeGen/PowerPC/no-misaligned-tocl.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
index 5d381a9540d9b..5b7761fb2d0df 100644
--- a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
+++ b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
@@ -839,7 +839,8 @@ bool PPCMIPeephole::simplifyCode() {
           if (SrcMI->getOperand(1).isGlobal()) {
             const GlobalObject *GO =
                 dyn_cast<GlobalObject>(SrcMI->getOperand(1).getGlobal());
-            if (GO && GO->getAlign() && *GO->getAlign() >= 4)
+            if (GO && GO->getAlign() && *GO->getAlign() >= 4 &&
+                (SrcMI->getOperand(1).getOffset() % 4 == 0))
               IsWordAligned = true;
           } else if (SrcMI->getOperand(1).isImm()) {
             int64_t Value = SrcMI->getOperand(1).getImm();

diff  --git a/llvm/test/CodeGen/PowerPC/no-misaligned-tocl.ll b/llvm/test/CodeGen/PowerPC/no-misaligned-tocl.ll
index f278411667daa..e5fc7dd2b742d 100644
--- a/llvm/test/CodeGen/PowerPC/no-misaligned-tocl.ll
+++ b/llvm/test/CodeGen/PowerPC/no-misaligned-tocl.ll
@@ -11,8 +11,9 @@ define dso_local signext i32 @main() #0 {
 ; CHECK:       # %bb.0: # %bb
 ; CHECK-NEXT:    addis r3, r2, var at toc@ha
 ; CHECK-NEXT:    lis r4, 0
-; CHECK-NEXT:    lwa r3, var at toc@l+7(r3)
+; CHECK-NEXT:    lwz r3, var at toc@l+7(r3)
 ; CHECK-NEXT:    ori r4, r4, 50000
+; CHECK-NEXT:    extsw r3, r3
 ; CHECK-NEXT:    sub r3, r3, r4
 ; CHECK-NEXT:    addis r4, r2, ans at toc@ha
 ; CHECK-NEXT:    rldicl r3, r3, 1, 63


        


More information about the llvm-commits mailing list