LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 18316 - [powerpc-darwin][AsmPrinter] addis instruction expects 0 instead of r0
Summary: [powerpc-darwin][AsmPrinter] addis instruction expects 0 instead of r0
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: PowerPC (show other bugs)
Version: trunk
Hardware: Macintosh MacOS X
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-23 23:33 PST by David Fang
Modified: 2014-03-06 12:16 PST (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments
function containing faulty addis instruction (3.51 KB, application/x-bzip2)
2013-12-24 11:21 PST, David Fang
Details
-S -emit-llvm (13.46 KB, text/plain)
2014-01-20 16:51 PST, David Fang
Details
bugpoint reduced test case (8.01 KB, application/octet-stream)
2014-03-05 19:12 PST, Hal Finkel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Fang 2013-12-23 23:33:04 PST
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.
Comment 1 Hal Finkel 2013-12-23 23:56:20 PST
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).
Comment 2 David Fang 2013-12-24 11:21:01 PST
Created attachment 11778 [details]
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).
Comment 3 David Fang 2014-01-08 21:06:12 PST
reduced test case PR18316.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 PR18316.o -c PR18316.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 PR18316.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/PR18316.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 PR18316.s -x c++-cpp-output PR18316.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 PR18316.o PR18316.s
PR18316.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 PR18316.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.
Comment 4 David Fang 2014-01-17 17:59:20 PST
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.
Comment 5 Hal Finkel 2014-01-20 14:47:20 PST
(In reply to comment #3)
> reduced test case PR18316.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 PR18316.o -c PR18316.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 PR18316.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/PR18316.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 PR18316.s -x
> c++-cpp-output PR18316.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 PR18316.o PR18316.s
> PR18316.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 PR18316.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).
Comment 6 David Fang 2014-01-20 16:51:34 PST
Created attachment 11910 [details]
-S -emit-llvm
Comment 7 Hal Finkel 2014-02-01 23:55:39 PST
(In reply to comment #6)
> 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).
Comment 8 David Fang 2014-02-04 05:41:54 PST
(In reply to comment #7)
> (In reply to comment #6)
> > 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 PR18316.o -c PR18316.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 PR18316.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/PR18316.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 PR18316.s -x c++-cpp-output PR18316.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 PR18316.o PR18316.s
PR18316.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)
Comment 9 David Fang 2014-02-04 05:42:50 PST
I'm sync'd to r200717.
Comment 10 David Fang 2014-02-25 16:03:27 PST
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 PR18316.ll -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v -coverage-file /var/tmp/PR18316-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/PR18316 -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/PR18316-8d1aa6.s -x ir PR18316.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/PR18316-8d1aa6.s
/var/tmp/PR18316-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)
Comment 11 David Fang 2014-02-25 16:16:52 PST
(In reply to comment #10)
> 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 PR18316.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.
Comment 12 Hal Finkel 2014-03-05 19:12:37 PST
Created attachment 12194 [details]
bugpoint reduced test case

I used bugpoint with a custom compile command to reduce the original test case.
Comment 13 Hal Finkel 2014-03-05 19:29:34 PST
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.
Comment 14 David Fang 2014-03-06 12:16:53 PST
Fix confirmed on powerpc-darwin8!  (I now get r30 where there was r0 before.)
Thanks!