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

Regression(r272251): error in backend: Cannot select: t45: i32 = ARMISD::BFI t4, Constant:i32<1>, t34 #28722

Closed
nico opened this issue Jun 28, 2016 · 10 comments
Labels
backend:ARM bugzilla Issues migrated from bugzilla

Comments

@nico
Copy link
Contributor

nico commented Jun 28, 2016

Bugzilla Link 28348
Resolution FIXED
Resolved on Jul 04, 2016 11:43
Version trunk
OS Linux
CC @compnerd,@jmolloy,@rengolin

Extended Description

thakis@thakis:/tmp$ cat repro.cc
struct A { A(char*); };

struct D : A {
D(char* p1) : A(p1) {}
};

class C {
void m_fn1(int a);
char *ValidateFrame_data_ptr;
};
void C::m_fn1(int a) {
D(new char[a & ~4095]);
ValidateFrame_data_ptr += 4096 + (a & 4095);
}
thakis@thakis:/tmp$ $HOME/src/llvm-build/bin/clang-3.8 -cc1 -triple thumbv7--linux-android -emit-obj -Os repro.cc
fatal error: error in backend: Cannot select: t45: i32 = ARMISD::BFI t4, Constant:i32<1>, t34
t4: i32,ch = CopyFromReg t0, Register:i32 %vreg1
t3: i32 = Register %vreg1
t44: i32 = Constant<1>
t34: i32 = t2MOVi16 TargetConstant:i32<4095>, TargetConstant:i32<14>, Register:i32 %noreg
t56: i32 = TargetConstant<4095>
t51: i32 = TargetConstant<14>
t52: i32 = Register %noreg
In function: _ZN1C5m_fn1Ei

@nico
Copy link
Contributor Author

nico commented Jun 28, 2016

Looking through svn log lib/Target/ARM/ | less, maybe r272251?

@nico
Copy link
Contributor Author

nico commented Jun 28, 2016

Yup, reverting that locally makes the assert go away. James, does this look like an easy fix, or should we revert?

@nico
Copy link
Contributor Author

nico commented Jun 28, 2016

Also, do you see an easy workaround around this crash until we can deploy a fixed compiler?

@nico
Copy link
Contributor Author

nico commented Jun 28, 2016

Workaround: Use volatile int kPad = 4095; and then s/4095/kPad/ :-P

@rengolin
Copy link
Member

Workaround: Use volatile int kPad = 4095; and then s/4095/kPad/ :-P

Hum, this sounds like constant folding / CSE, and not a case Jame's patch [1] was testing for.

Probably this has provided a case which he wasn't expecting, and the testing wasn't really that thorough... :/

Maybe reverting the patch for now would be a good thing, unless James has a quick fix (and more tests!).

cheers,
--renato

[1] http://llvm.org/viewvc/llvm-project?view=revision&revision=272251

@nico
Copy link
Contributor Author

nico commented Jun 29, 2016

Hm, this might fix it:

Index: lib/Target/ARM/ARMISelDAGToDAG.cpp

--- lib/Target/ARM/ARMISelDAGToDAG.cpp (revision 274127)
+++ lib/Target/ARM/ARMISelDAGToDAG.cpp (working copy)
@@ -2835,11 +2835,11 @@
Subtarget->hasThumb2() && !is_t2_so_imm(Imm) && is_t2_so_imm_not(Imm);
if (!PreferImmediateEncoding &&
ConstantMaterializationCost(Imm) >

  •          ConstantMaterializationCost(~Imm)) {
    
  •          ConstantMaterializationCost(-Imm)) {
       // The current immediate costs more to materialize than a negated
       // immediate, so negate the immediate and use a BIC.
       SDValue NewImm =
    
  •        CurDAG->getConstant(~N1C->getZExtValue(), dl, MVT::i32);
    
  •        CurDAG->getConstant(-N1C->getZExtValue(), dl, MVT::i32);
       CurDAG->RepositionNode(N->getIterator(), NewImm.getNode());
    
       if (!Subtarget->hasThumb2()) {
    

@nico
Copy link
Contributor Author

nico commented Jun 29, 2016

Hm no, that's not good, BIC is AND NOT.

@nico
Copy link
Contributor Author

nico commented Jun 29, 2016

$ svn commit -m 'Revert r272251, it caused #28722 .'
Sending lib/Target/ARM/ARMISelDAGToDAG.cpp
Deleting test/CodeGen/Thumb/bic_imm.ll
Transmitting file data .
Committed revision 274141.

$ svn commit -m 'Add a regression test for #28722 .'
Adding test/CodeGen/Thumb/and_neg.ll
Transmitting file data .
Committed revision 274142.

@compnerd
Copy link
Member

reduced.c
Add an additional, slightly larger test case.

@jmolloy
Copy link

jmolloy commented Jul 4, 2016

Hi Nico,

Thanks for bringing this to my attention, and sorry that I didn't act on it quickly as I was on vacation.

The underlying problem is actually my use of DAG->getConstant. I should be using DAG->getTargetConstant.

The use of getConstant() in this testcase actually increments the use count of Constant<4095> from one to two. In this case, the lowering of ARMISD::BFI is contingent on its constant argument only having one use - if it's shared, ISel falls over.

I've committed a fixed version in r274510.

Cheers,

James

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 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:ARM bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

4 participants