<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hi folks,<br class="">
<br class="">
I'm hitting the below assertion failure when compiling this small piece of C code (repro.c, attached).<br class="">
<br class="">
My command line is:<br class="">
<br class="">
<font face="Courier" class="">bin/clang --target=aarch64-linux-gnu -c -O2 repro.c<br class="">
</font><br class="">
clang is built from top of trunk as of this morning. It only happens at -O2, and it doesn't happen with the default target (x86_64). I tried to reproduce using just 'llc -O2' but didn't manage -- but I do have this reduced opt command line (repro.ll also attached, just
 generated from repro.c at -O0):<br class="">
<br class="">
<font face="Courier" class="">bin/opt -instcombine -licm -simplifycfg -instcombine -loop-rotate -loop-vectorize -instcombine < repro.ll<br class="">
</font><br class="">
The failure is:<br class="">
<br class="">
<font face="Courier" class="">opt: /scratch/1/ismail/llvm-upstream/include/llvm/ADT/APInt.h:983: bool llvm::APInt::operator==(const llvm::APInt&) const: Assertion `BitWidth == RHS.BitWidth && "Comparison requires equal bit widths"' failed.<br class="">
...snip...<br class="">
#8 0x00000000013a8553 llvm::APInt::operator==(llvm::APInt const&) const /scratch/1/ismail/llvm-upstream/include/llvm/ADT/APInt.h:984:0<br class="">
#9 0x0000000001f875b0 simplifySelectBitTest(llvm::Value*, llvm::Value*, llvm::Value*, llvm::APInt const*, bool) /scratch/1/ismail/llvm-upstream/lib/Analysis/InstructionSimplify.cpp:3388:0<br class="">
#10 0x0000000001f87ad5 simplifySelectWithICmpCond(llvm::Value*, llvm::Value*, llvm::Value*, (anonymous namespace)::Query const&, unsigned int) /scratch/1/ismail/llvm-upstream/lib/Analysis/InstructionSimplify.cpp:3434:0<br class="">
#11 0x0000000001f87f6a SimplifySelectInst(llvm::Value*, llvm::Value*, llvm::Value*, (anonymous namespace)::Query const&, unsigned int) /scratch/1/ismail/llvm-upstream/lib/Analysis/InstructionSimplify.cpp:3515:0<br class="">
#12 0x0000000001f87fe3 llvm::SimplifySelectInst(llvm::Value*, llvm::Value*, llvm::Value*, llvm::DataLayout const&, llvm::TargetLibraryInfo const*, llvm::DominatorTree const*, llvm::AssumptionCache*, llvm::Instruction const*) /scratch/1/ismail/llvm-upstream/lib/Analysis/InstructionSimplify.cpp:3528:0<br class="">
...snip...<br class="">
Stack dump:<br class="">
0.  Program arguments: debugbuild/bin/opt -instcombine -licm -simplifycfg -instcombine -loop-rotate -loop-vectorize -instcombine<br class="">
1.  Running pass 'Function Pass Manager' on module '<stdin>'.<br class="">
2.  Running pass 'Combine redundant instructions' on function '@strsave'</font><br class="">
<br class="">
---<br class="">
<br class="">
Looking at the code, the issue is with this line:<br class="">
<br class="">
<font face="Courier" class="">  if (TrueVal == X && match(FalseVal, m_And(m_Specific(X), m_APInt(C))) &&<br class="">
        *Y == ~*C)</font><br class="">
<br class="">
In this case Y is a 128-bit APInt, and so is the value that C is extracted from, but the m_APInt matcher has code that calls getSplatValue() if the matched expression has vector type. So C ends up as an 8-bit value, triggering the assertion failure on the call
 to ==.<br class="">
<br class="">
The issue is clear but I'm not sure what the correct fix should be -- whether this code is just not meant to work with vector types, or whether the call to getSplatValue() doesn't belong in the matcher, or whether there should be a corresponding call to getSplatValue()
 on the caller side, or something else.<br class="">
<br class="">
Any help from someone with more context would be appreciated.<br class="">
<br class="">
Thanks,<br class="">
Ismail
<div class=""><br class="">
</div>
<div class=""></div>
</body>
</html>