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

[powerpc-darwin][AsmPrinter] addis instruction expects 0 instead of r0 #18690

Closed
llvmbot opened this issue Dec 24, 2013 · 14 comments
Closed

[powerpc-darwin][AsmPrinter] addis instruction expects 0 instead of r0 #18690

llvmbot opened this issue Dec 24, 2013 · 14 comments
Labels
backend:PowerPC bugzilla Issues migrated from bugzilla

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 24, 2013

Bugzilla Link 18316
Resolution FIXED
Resolved on Mar 06, 2014 12:16
Version trunk
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @hfinkel,@iains

Extended Description

During my stage-2 build of powerpc-darwin8 clang, stage-1 clang was found to emit some assembly that was rejected by the system assembler (including the 'as' from odcctools-2009).

% cat addis.s
addis r30, 0, 1 ; OK
addis r30, r1, 1 ; OK
addis r30, r0, 1 : rejected

% as addis.s -o addis.o
addis.s:3:Parameter error: r0 not allowed for parameter 2 (code as 0 not r0)

Apparently, r0 is special enough to warrant different syntax in certain contexts.
Would it be possible to emit such instructions differently?

The PPC darwin asm parser, accepts all of the above:

% ~/local/src/LLVM-svn/gcc40-cmake-build/bin/llvm-mc -triple powerpc-apple-darwin8 addis.s -filetype=obj -o addis.o

I don't mind keeping that as-is, but if you want tighter conformity, you could mimic the darwin assembler behavior.

I think it's more important to emit darwin-asm-friendly code so that -no-integrated-as continues to work.

@hfinkel
Copy link
Collaborator

hfinkel commented Dec 24, 2013

Odd; this should already have been fixed (ADDIS uses the gprc_nor0 input register class, which should use PPC::ZERO to represent r0, and PPC::ZERO should print as "0"). Can you tell from where this addis is coming?

(you can probably use bugpoint to create a reduced test case).

@llvmbot
Copy link
Collaborator Author

llvmbot commented Dec 24, 2013

function containing faulty addis instruction
The original error came from (stage-2, compiling -O0):

% /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++ -DLLVMX86CodeGen_EXPORTS -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include -fno-common -no-integrated-as -fno-dwarf2-cfi-asm -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -Wnon-virtual-dtor -fno-rtti -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fPIC -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Target/X86 -I/Users/fang/local/src/LLVM-svn/llvm/lib/Target/X86 -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/include -I/Users/fang/local/src/LLVM-svn/llvm/include -fno-exceptions -fno-exceptions -o CMakeFiles/LLVMX86CodeGen.dir/X86ISelLowering.cpp.o -c /Users/fang/local/src/LLVM-svn/llvm/lib/Target/X86/X86ISelLowering.cpp -save-temps
X86ISelLowering.s:126710:Parameter error: r0 not allowed for parameter 2 (code as 0 not r0)
clang-3.5: error: assembler command failed with exit code 1 (use -v to see invocation)

Attached is the asm of the function that contains the lone instance of addis rX, r0, Y

My workaround was to manually recompile this unit with -integrated-as (which then allowed stage-2 to finish).

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 9, 2014

reduced test case #18690 .ii:
struct Type;
struct MVT {
enum SimpleValueType { v4i32, v2i64 };
};
struct EVT {
MVT V;
Type* LLVMTy;
EVT(MVT::SimpleValueType);
bool operator == (EVT) const;
};

struct SDNode;

struct SDValue {
SDNode *Node;
unsigned ResNo;
EVT getValueType() const;
const SDValue &getOperand(unsigned) const;
};

struct SDLoc {
const void *Ptr;
int IROrder;
SDLoc(const SDValue) : Ptr(0), IROrder(-1) { }
};

struct ISD {
enum sd_e { BITCAST };
};

struct SelectionDAG {
SDValue getVectorShuffle(EVT, SDLoc, SDValue, SDValue, const int*);
SDValue getNode(unsigned, SDLoc, EVT, SDValue);
SDValue getNode(unsigned, SDLoc, EVT, SDValue, SDValue);
};

namespace X86ISD {
enum NodeType { PMULUDQ };
}

SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) {
SDLoc dl(Op);
EVT VT = Op.getValueType();
SDValue A = Op.getOperand(0);
SDValue B = Op.getOperand(1);
if (VT == MVT::v4i32) {
static const int UnpackMask[] = { 1, -1, 3, -1 };
SDValue Aodds = DAG.getVectorShuffle(VT, dl, A, A, UnpackMask);
SDValue Bodds = DAG.getVectorShuffle(VT, dl, B, B, UnpackMask);
SDValue Evens = DAG.getNode(X86ISD::PMULUDQ, dl, MVT::v2i64, A, B);
SDValue Odds = DAG.getNode(X86ISD::PMULUDQ, dl, MVT::v2i64, Aodds, Bodds);
Evens = DAG.getNode(ISD::BITCAST, dl, VT, Evens);
Odds = DAG.getNode(ISD::BITCAST, dl, VT, Odds);
static const int ShufMask[] = { 0, 4, 2, 6 };
return DAG.getVectorShuffle(VT, dl, Evens, Odds, ShufMask);
}
return Op;
}

invocation:
% /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++ -no-integrated-as -o #18690 .o -c #18690 .ii -save-temps -v
clang version 3.4
Target: powerpc-apple-darwin8.11.0
Thread model: posix
"/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.5" -cc1 -triple powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name #18690 .ii -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -target-cpu ppc -v -coverage-file /Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Target/X86/#18316 .s -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.4 -fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fno-autolink -fdebug-compilation-dir /Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Target/X86 -ferror-limit 19 -fmessage-length 80 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-fragile-10.4.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o #18690 .s -x c++-cpp-output #18690 .ii
clang -cc1 version 3.4 based upon LLVM 3.4git-bb410b7 default target powerpc-apple-darwin8.11.0
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.0.0
/usr/include/c++/4.0.0/powerpc-apple-darwin8
/usr/include/c++/4.0.0/backward
/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.4/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/as" -arch ppc -o #18690 .o #18690 .s
#18690 .s:463:Parameter error: r0 not allowed for parameter 2 (code as 0 not r0)
clang-3.5: error: assembler command failed with exit code 1 (use -v to see invocation)

% grep addis #18690 .s | grep r0
addis r30, r0, ha16(__ZZ8LowerMUL7SDValueR12SelectionDAGE8ShufMask-L0$pb)

I had trouble reducing further because the asm was sensitive to struct sizes and call sites. Hope this suffices.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 18, 2014

llvm-mc seems to do the right thing and print r0 as 0.

% cat in.s
addis r30, 0, 1 ; OK
addis r30, r1, 1 ; OK
addis r30, r0, 1 ; rejected
% llvm-mc -triple powerpc-apple-darwin8 -filetype=asm in.s -o out.s
% cat out.s
.section __TEXT,__text,regular,pure_instructions
addis r30, 0, 1

    addis r30, r1, 1

    addis r30, 0, 1

The output from the reduced test case might be going through some different code path to print that.

@hfinkel
Copy link
Collaborator

hfinkel commented Jan 20, 2014

reduced test case #18690 .ii:
struct Type;
struct MVT {
enum SimpleValueType { v4i32, v2i64 };
};
struct EVT {
MVT V;
Type* LLVMTy;
EVT(MVT::SimpleValueType);
bool operator == (EVT) const;
};

struct SDNode;

struct SDValue {
SDNode *Node;
unsigned ResNo;
EVT getValueType() const;
const SDValue &getOperand(unsigned) const;
};

struct SDLoc {
const void *Ptr;
int IROrder;
SDLoc(const SDValue) : Ptr(0), IROrder(-1) { }
};

struct ISD {
enum sd_e { BITCAST };
};

struct SelectionDAG {
SDValue getVectorShuffle(EVT, SDLoc, SDValue, SDValue, const int*);
SDValue getNode(unsigned, SDLoc, EVT, SDValue);
SDValue getNode(unsigned, SDLoc, EVT, SDValue, SDValue);
};

namespace X86ISD {
enum NodeType { PMULUDQ };
}

SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) {
SDLoc dl(Op);
EVT VT = Op.getValueType();
SDValue A = Op.getOperand(0);
SDValue B = Op.getOperand(1);
if (VT == MVT::v4i32) {
static const int UnpackMask[] = { 1, -1, 3, -1 };
SDValue Aodds = DAG.getVectorShuffle(VT, dl, A, A, UnpackMask);
SDValue Bodds = DAG.getVectorShuffle(VT, dl, B, B, UnpackMask);
SDValue Evens = DAG.getNode(X86ISD::PMULUDQ, dl, MVT::v2i64, A, B);
SDValue Odds = DAG.getNode(X86ISD::PMULUDQ, dl, MVT::v2i64, Aodds,
Bodds);
Evens = DAG.getNode(ISD::BITCAST, dl, VT, Evens);
Odds = DAG.getNode(ISD::BITCAST, dl, VT, Odds);
static const int ShufMask[] = { 0, 4, 2, 6 };
return DAG.getVectorShuffle(VT, dl, Evens, Odds, ShufMask);
}
return Op;
}

invocation:
% /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++
-no-integrated-as -o #18690 .o -c #18690 .ii -save-temps -v
clang version 3.4
Target: powerpc-apple-darwin8.11.0
Thread model: posix
"/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.5" -cc1 -triple
powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name #18690 .ii
-mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose
-target-cpu ppc -v -coverage-file
/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Target/X86/#18316 .s
-resource-dir
/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.4
-fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm
-fno-autolink -fdebug-compilation-dir
/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Target/X86
-ferror-limit 19 -fmessage-length 80 -mstackrealign -fblocks
-fblocks-runtime-optional -fobjc-runtime=macosx-fragile-10.4.0
-fencode-extended-block-signature -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o #18690 .s -x
c++-cpp-output #18690 .ii
clang -cc1 version 3.4 based upon LLVM 3.4git-bb410b7 default target
powerpc-apple-darwin8.11.0
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.0.0
/usr/include/c++/4.0.0/powerpc-apple-darwin8
/usr/include/c++/4.0.0/backward
/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.4/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/as" -arch ppc -o #18690 .o #18690 .s
#18690 .s:463:Parameter error: r0 not allowed for parameter 2 (code as 0 not
r0)
clang-3.5: error: assembler command failed with exit code 1 (use -v to see
invocation)

% grep addis #18690 .s | grep r0
addis r30, r0,
ha16(__ZZ8LowerMUL7SDValueR12SelectionDAGE8ShufMask-L0$pb)

I had trouble reducing further because the asm was sensitive to struct sizes
and call sites. Hope this suffices.

Please attach the input LLVM IR, so that I can debug this problem. (running Clang with -S -emit-llvm should do it).

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 21, 2014

-S -emit-llvm

@hfinkel
Copy link
Collaborator

hfinkel commented Feb 2, 2014

Created attachment 11910 [details]
-S -emit-llvm

At least as of r200461, I don't see any addis instructions generated from this input (running it through llc or llc -O0).

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 4, 2014

Created attachment 11910 [details]
-S -emit-llvm

At least as of r200461, I don't see any addis instructions generated from
this input (running it through llc or llc -O0).

The original test case X86ISelLowering.cpp no longer triggers the error, however, the reduced test case from comment 3 still does:

% /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++ -no-integrated-as -o #18690 .o -c #18690 .ii -save-temps -v
clang version 3.5
Target: powerpc-apple-darwin8.11.0
Thread model: posix
"/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.5" -cc1 -triple powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name #18690 .ii -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v -coverage-file /Volumes/Isolde/builds/LLVM/gcc40-stage2-build/lib/Target/X86/#18316 .s -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.5 -fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fno-autolink -fdebug-compilation-dir /Volumes/Isolde/builds/LLVM/gcc40-stage2-build/lib/Target/X86 -ferror-limit 19 -fmessage-length 100 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o #18690 .s -x c++-cpp-output #18690 .ii
clang -cc1 version 3.5 based upon LLVM 3.5git-591140e default target powerpc-apple-darwin8.11.0
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.0.0
/usr/include/c++/4.0.0/powerpc-apple-darwin8
/usr/include/c++/4.0.0/backward
/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.5/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/as" -arch ppc -o #18690 .o #18690 .s
#18690 .s:463:Parameter error: r0 not allowed for parameter 2 (code as 0 not r0)
clang-3.5: error: assembler command failed with exit code 1 (use -v to see invocation)

Can you try that test case with the above cc1 command? (instead of the .ll)

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 4, 2014

I'm sync'd to r200717.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 26, 2014

I had trouble getting llc to fail on the already attached .ll, but clang was able to use it:

"/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.5" -cc1 -triple powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name #18690 .ll -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v -coverage-file /var/tmp/#18316 -8d1aa6.s -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.5 -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fno-autolink -fdebug-compilation-dir /Users/fang/temp/clang/#18316 -ferror-limit 19 -fmessage-length 80 -mstackrealign -malign-power -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fencode-extended-block-signature -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/tmp/#18316 -8d1aa6.s -x ir #18690 .ll
clang -cc1 version 3.5 based upon LLVM 3.5git-c01afce default target powerpc-apple-darwin8.11.0
"/usr/bin/as" -arch ppc -o temp.o /var/tmp/#18316 -8d1aa6.s
/var/tmp/#18316 -8d1aa6.s:463:Parameter error: r0 not allowed for parameter 2 (code as 0 not r0)
clang-3.5: error: assembler command failed with exit code 1 (use -v to see invocation)

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 26, 2014

I had trouble getting llc to fail on the already attached .ll, but clang was
able to use it:

even simpler cc1:
clang -cc1 -triple powerpc-apple-macosx10.4.0 -S -v -o temp.s -x ir #18690 .ll

temp.s should contain around line 467:
addis r30, r0, ha16(__ZZ8LowerMUL7SDValueR12SelectionDAGE8ShufMask-L0$pb)

Also reproducible with -fno-dwarf2-cfi-asm, which is needed on darwin8.

@hfinkel
Copy link
Collaborator

hfinkel commented Mar 6, 2014

bugpoint reduced test case
I used bugpoint with a custom compile command to reduce the original test case.

@hfinkel
Copy link
Collaborator

hfinkel commented Mar 6, 2014

The ADDIS is coming from the regular add pattern:

ISEL: Starting pattern match on root node: 0x70b7480: i32 = add 0x70b4430, 0x70b2c70 [ORD=29] [ID=66]
...
Morphed node: 0x70b7480: i32 = ADDIS 0x70b4430, 0x70b2170 [ORD=29]

which was:

          0x70b4430: i32 = PPCISD::GlobalBaseReg [ORD=29]

          0x70b2c70: i32 = PPCISD::Hi 0x70b2170, 0x70b4030 [ORD=29]

        0x70b7480: i32 = add 0x70b4430, 0x70b2c70 [ORD=29]

If we make sure to allocate the global base register from the non-r0 register class, then this problem goes away ;) -- r203054.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Mar 6, 2014

Fix confirmed on powerpc-darwin8! (I now get r30 where there was r0 before.)
Thanks!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:PowerPC bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

2 participants