Bug type: crash
Component: LazyValueInfo
Bug location: llvm/lib/Analysis/LazyValueInfo.cpp: LazyValueInfo::getConstantOnEdge
Issue title: A/F: `getType() == V->getType() && "All operands to PHI node must be the same type as the PHI node !"' after 1eec81a
Labels: crash
llvm:analysis
Reported by: dyung

We have an internal test which started to hit an assertion failure when compiled which I bisected back to 1eec81a.

Consider the following code:
```c++
template <bool, class, class> using c = int;
typedef long cb __attribute__((__vector_size__(16)));
cb d(cb);
typedef long e __attribute__((__vector_size__(32)));
enum { f };
struct g {
  enum { h };
};
template <typename> struct i;
template <typename> struct aa;
template <typename> struct j;
template <typename> class k;
template <typename, int l, int m, int = 0, int = l, int = m> class n;
template <typename, typename> class o;
template <typename, int l, int m, int = 0, int = l, int = m> class p;
template <typename> struct q;
template <typename> struct r;
template <typename s> struct t { typedef q
::ab ab; };
template <typename ac> struct ad { typedef k<ac> ab; };
template <typename s> struct u {
  operator s() { return ae; }
  u(s v) : ae(v) {}
  s ae;
};
template <typename w> w x(const typename r<w>::ab &);
template <> struct q<int> { typedef u<e> ab; };
template <> struct r<u<e>> {
  typedef int ab;
  enum { af = 8 };
};
template <> u<e> x(const int &) {
  e y{};
  return y;
}
e z;
e ag(e a, u<e> b) {
  __attribute__((__vector_size__(4 * sizeof(long)))) long ah = b;
  z = a + ah;
  return z;
}
struct ai {
  u<__attribute__((__vector_size__(4 * sizeof(long)))) long>
  aj(u<__attribute__((__vector_size__(4 * sizeof(long)))) long> a,
     const u<__attribute__((__vector_size__(4 * sizeof(long)))) long> &b) {
    __attribute__((__vector_size__(4 * sizeof(long)))) long ak = a;
    return ag(ak, b);
  }
};
struct al {
  template <typename am> am aj() { return x<am>(an); }
  int an;
};
template <typename ac> long ao(ac);
template <typename ac> class k : j<ac> {
public:
  typedef i<ac>::ap ap;
  using j<ac>::aq;
  static o<int, c<g::h, ac, p<ac, i<ac>::ar, i<ac>::as>>> at(long, long);
  ap au() const;
  template <typename av> ap aw(const av &) const;
};
template <typename ac> struct j { ac aq() const; };
struct ax {
  template <typename s, typename ay> s aj(al az, ay) { return az.aj
(); }
};
template <typename ba, typename bb> struct aa<o<ba, bb>> {
  aa(o<ba, bb>);
  template <int, typename am, typename ay> am bc(ay) {
    return be.aj<am>(bf, d);
  }
  ba bf;
  ax be;
};
template <typename ac> class bg : public ad<ac>::ab {};
template <typename bh, int l, int m, int bi, int bj, int bk>
struct i<n<bh, l, m, bi, bj, bk>> {
  typedef bh ap;
  enum { ar, as };
};
template <typename bh, int l, int m, int bi, int bj, int bk>
struct i<p<bh, l, m, bi, bj, bk>> : i<n<bh, bj, bk>> {};
template <typename, int, int, int, int bj, int bk>
class p : public bg<p<int, bj, bk>> {};
template <typename ba, typename bb> struct i<o<ba, bb>> : i<bb> {};
template <typename, typename>
class o : public ad<o<al, p<int, 0, -1, 1, 0, 1>>>::ab {};
template <typename bl> struct bm {
  typedef t<typename bl::ap>::ab am;
  enum { bn = r<am>::af };
  enum { bo };
};
template <typename, typename bl, int = bm<bl>::bo> struct M;
template <typename bp, typename bl> struct M<bp, bl, f> {
  typedef bm<bl>::am bq;
  template <typename br> static bl bs(bl bt, bp bu, br bv) {
    enum { alignment };
    long bw = ao(bv);
    bq bx = bt.template bc<alignment, bq>(bw);
    if (bw > bm<bl>::bn) {
      bq by = bt.template bc<alignment, bq>(bm<bl>::bn);
      for (long bd; bd; bd += bm<bl>::bn) {
        bx = bu.aj(bx, bt.template bc<alignment, bq>(d));
        u bz = bt.template bc<alignment, bq>(bm<bl>::bn);
        by = bu.aj(by, bz);
      }
      bx = bu.aj(bx, by);
    }
    __attribute__((__vector_size__(4 * sizeof(int)))) int ca =
        __builtin_ia32_vextractf128_si256(bx, 0);
    __attribute__((__vector_size__(2 * sizeof(long)))) long b = d(ca);
  }
};
class cc : public aa<o<al, p<int, 0, -1, 1, 0, 1>>> {
public:
  typedef int ap;
};
template <typename ac>
template <typename bp>
i<ac>::ap k<ac>::aw(const bp &bu) const {
  cc cd(aq());
  o<int, int> ce;
  M<bp, cc>::bs(cd, bu, ce);
}
template <typename ac> i<ac>::ap k<ac>::au() const { aw(ai()); }
void cf() { p<int, 1, 1>::at(0, 0).au(); }
```

When compiled with optimizations and AVX support with a compiler before 1eec81a, the compilation succeeds:
```
$ ~/src/upstream/b76dd4edbfbba5593b691ef92b755f25cf63f445-linux/bin/clang -c -O2 -mavx -Wno-return-type -std=c++20 repro.cpp
$
```

When compiled with the same arguments but with a compiler built from 1eec81a, the compiler hits an assertion failure:
```
$ ~/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang -c -O2 -mavx -Wno-return-type -std=c++20 repro.cpp
clang: /home/dyung/src/upstream/llvm_clean_git/llvm/include/llvm/IR/Instructions.h:2582: void llvm::PHINode::setIncomingValue(unsigned int, llvm::Value*): Assertion `getType() == V->getType() && "All operands to PHI node must be the same type as the PHI node
!"' failed.                           
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.                                                                                                       
Stack dump:
0.      Program arguments: /home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang -c -O2 -mavx -Wno-return-type -std=c++20 repro.cpp
1.      <eof> parser at end of file
2.      Optimizer
3.      Running pass "require<globals-aa>,function(invalidate<aa>),require<profile-summary>,cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-
execution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-
branch>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-in
sts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-un
switch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,instcombine<max-iterations=1;no-use
-loop-info;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-unswitch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-use-loop-info;
no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-commo
n-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split)),function(invalidate<should-not-run-function-pass
es>),cgscc(devirt<4>())" on module "repro.cpp"
4.      Running pass "cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagat
ion,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoi
nt>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,reasso
ciate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-f
orward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-uns
witch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyo
pt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,instc
ombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split))" on module "repro.cpp"
5.      Running pass "correlated-propagation" on function "_ZN1MI2ai2ccLi0EE2bsI1oIiiEEES1_S1_S0_T_"
 #0 0x000056411be676af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x41856af)
 #1 0x000056411be6520c llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x418320c)
 #2 0x000056411bdaa728 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f29a8886420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f29a835300b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f29a8332859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f29a8332729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f29a8332729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f29a8343fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x00005641200199a5 processPHI(llvm::PHINode*, llvm::LazyValueInfo*, llvm::DominatorTree*, llvm::SimplifyQuery const&) CorrelatedValuePropagation.cpp:0:0
#10 0x000056412002131e runImpl(llvm::Function&, llvm::LazyValueInfo*, llvm::DominatorTree*, llvm::SimplifyQuery const&) CorrelatedValuePropagation.cpp:0:0
#11 0x0000564120022b4b llvm::CorrelatedValuePropagationPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x8340b4b)
#12 0x000056411d2b9866 llvm::detail::PassModel<llvm::Function, llvm::CorrelatedValuePropagationPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d7866)
#13 0x000056411b80daf1 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x3b2baf1)
#14 0x00005641193e3d86 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x1701d86)
#15 0x000056411acf6e91 llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x3014e91)
#16 0x00005641193e5326 llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::CGSCCToFunctionPassAdaptor, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x1703326)
#17 0x000056411aceef7f llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x300cf7f)
#18 0x000056411d2b71b6 llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d51b6)
#19 0x000056411acf370d llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x301170d)
#20 0x000056411d2b7206 llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::DevirtSCCRepeatedPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d5206)
#21 0x000056411acf150c llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x300f50c)
#22 0x000056411d2b7166 llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d5166)
#23 0x000056411b80a601 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x3b28601)
#24 0x000056411d4afdb5 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x57cddb5)
#25 0x000056411d2b68f6 llvm::detail::PassModel<llvm::Module, llvm::ModuleInlinerWrapperPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d48f6)
#26 0x000056411b80a601 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x3b28601)
#27 0x000056411c11c4d8 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#28 0x000056411c11f855 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#29 0x000056411c11fef6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x443def6)
#30 0x000056411c792bea clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4ab0bea)
#31 0x000056411e56cb8c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x688ab8c)
#32 0x000056411c793078 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4ab1078)
#33 0x000056411ca26e79 clang::FrontendAction::Execute() (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4d44e79)
#34 0x000056411c9aa76e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4cc876e)
#35 0x000056411cb12366 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4e30366)
#36 0x0000564118fcc89f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x12ea89f)
#37 0x0000564118fc594a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#38 0x000056411c7d833d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#39 0x000056411bdaac30 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x40c8c30)
#40 0x000056411c7d895f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#41 0x000056411c79cdbc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4abadbc)
#42 0x000056411c79d84d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4abb84d)
#43 0x000056411c7a5925 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4ac3925)
#44 0x0000564118fc9bab clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x12e7bab)
#45 0x0000564118ebcc0b main (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x11dac0b)
#46 0x00007f29a8334083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#47 0x0000564118fc53de _start (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x12e33de)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 19.0.0 (https://github.com/llvm/llvm-project.git 1eec81a831dcf925c0c86c153e8dce019a5b5436)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin
```

Comments: author: goldsteinn
body: Seems like when `CVP` finds a constant, its returning the scalar, not the VEC type.

Reducer of exact error:
```
define <4 x i64> @reduce(i1 %cond) {
entry:
  br i1 %cond, label %if.then, label %if.end

if.then:
  %folds = add <4 x i64> zeroinitializer, <i64 1, i64 1, i64 1, i64 1>
  br label %if.end

if.end:
  %r = phi <4 x i64> [ %folds, %if.then ], [ zeroinitializer, %entry ]
  ret <4 x i64> %r
}
```
Repro with: `opt  -passes=correlated-propagation`

Or an even simpler version (different assert location):
```
define <4 x i64> @reduce() {
entry:
  %folds = add <4 x i64> zeroinitializer, zeroinitializer
  ret <4 x i64> %folds
}
    
```

Same command as above.

author: goldsteinn
body: Ill have a fix up shortly.
author: goldsteinn
body: Fix at: https://github.com/llvm/llvm-project/pull/97682

Fix patch:
commit 899fe2cf318f6e3c7a183125ff17ef53944b2989
Author: goldsteinn <35538541+goldsteinn@users.noreply.github.com>
Date:   Thu Jul 4 15:14:39 2024 +0800

    [CVP][LVI] Fix incorrect scalar type when getting constant folded vec (#97682)
    
    Fixes #97674
    
    After #97428 added support for vectors, our constant ranges can now be
    from splat vectors so when they reduce to a singe constant value, we
    need to return the original type as opposed to just an int.

diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index b30e6a6a367c..4209ee4a7795 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1370,6 +1370,7 @@ LazyValueInfoImpl::getEdgeValueLocal(Value *Val, BasicBlock *BBFrom,
 
       // If V is the condition of the branch itself, then we know exactly what
       // it is.
+      // NB: The condition on a `br` can't be a vector type.
       if (Condition == Val)
         return ValueLatticeElement::get(ConstantInt::get(
                               Type::getInt1Ty(Val->getContext()), isTrueDest));
@@ -1723,7 +1724,7 @@ Constant *LazyValueInfo::getConstant(Value *V, Instruction *CxtI) {
   if (Result.isConstantRange()) {
     const ConstantRange &CR = Result.getConstantRange();
     if (const APInt *SingleVal = CR.getSingleElement())
-      return ConstantInt::get(V->getContext(), *SingleVal);
+      return ConstantInt::get(V->getType(), *SingleVal);
   }
   return nullptr;
 }
@@ -1758,7 +1759,7 @@ Constant *LazyValueInfo::getConstantOnEdge(Value *V, BasicBlock *FromBB,
   if (Result.isConstantRange()) {
     const ConstantRange &CR = Result.getConstantRange();
     if (const APInt *SingleVal = CR.getSingleElement())
-      return ConstantInt::get(V->getContext(), *SingleVal);
+      return ConstantInt::get(V->getType(), *SingleVal);
   }
   return nullptr;
 }


Regression tests:
file: llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
commands: opt -S -passes=correlated-propagation < %s
tests: test_name: and_with_poison
test_body: define <2 x i16> @and_with_poison(<2 x i8> %a) {
  %zext = zext <2 x i8> %a to <2 x i16>
  %res = and <2 x i16> %zext, <i16 255, i16 poison>
  ret <2 x i16> %res
}

test_name: issue_97674_getConstant
test_body: define <4 x i64> @issue_97674_getConstant() {
entry:
  %folds = add <4 x i64> zeroinitializer, zeroinitializer
  ret <4 x i64> %folds
}

test_name: issue_97674_getConstantOnEdge
test_body: define <4 x i64> @issue_97674_getConstantOnEdge(i1 %cond) {
entry:
  br i1 %cond, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  %folds = add <4 x i64> zeroinitializer, splat (i64 1)
  br label %if.end

if.end:                                           ; preds = %if.then, %entry
  %r = phi <4 x i64> [ %folds, %if.then ], [ zeroinitializer, %entry ]
  ret <4 x i64> %r
}