<div dir="ltr">Was this covered by existing tests (but only exposed on some buildbot or another configuration that tickled the UB into being more problematic?)?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Apr 24, 2021 at 10:44 AM Dávid Bolvanský via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Dávid Bolvanský<br>
Date: 2021-04-24T19:44:16+02:00<br>
New Revision: 137568e5797c33c12d284cc325367ceaddf2441a<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/137568e5797c33c12d284cc325367ceaddf2441a" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/137568e5797c33c12d284cc325367ceaddf2441a</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/137568e5797c33c12d284cc325367ceaddf2441a.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/137568e5797c33c12d284cc325367ceaddf2441a.diff</a><br>
<br>
LOG: [InstCombine] Fixed UB in foldCtpop<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp<br>
index 378682b7b9cd..72008dfa3b28 100644<br>
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp<br>
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp<br>
@@ -497,7 +497,7 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {<br>
   Type *Ty = II.getType();<br>
   unsigned BitWidth = Ty->getScalarSizeInBits();<br>
   Value *Op0 = II.getArgOperand(0);<br>
-  Value *X;<br>
+  Value *X, *Y;<br>
<br>
   // ctpop(bitreverse(x)) -> ctpop(x)<br>
   // ctpop(bswap(x)) -> ctpop(x)<br>
@@ -505,8 +505,9 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {<br>
     return IC.replaceOperand(II, 0, X);<br>
<br>
   // ctpop(rot(x)) -> ctpop(x)<br>
-  if (match(Op0, m_FShl(m_Value(X), m_Specific(X), m_Value())) ||<br>
-      match(Op0, m_FShr(m_Value(X), m_Specific(X), m_Value())))<br>
+  if ((match(Op0, m_FShl(m_Value(X), m_Value(Y), m_Value())) ||<br>
+       match(Op0, m_FShr(m_Value(X), m_Value(Y), m_Value()))) &&<br>
+      X == Y)<br>
     return IC.replaceOperand(II, 0, X);<br>
<br>
   // ctpop(x | -x) -> bitwidth - cttz(x, false)<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>