<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div class="" style="word-wrap:break-word">
<div class="">In the current mangling scheme for overloaded intrinsics we include overloaded type names in the intrinsic name. For example:</div>
<div class=""><br class="">
</div>
<div class="">%struct.foobar = type { i32 }</div>
<div class="">declare <4 x %struct.foobar*> @llvm.masked.load.v4p0struct.foobar(<4 x %struct.foobar*>*, i32, <4 x i1>, <4 x %struct.foobar*>)</div>
<div class=""><br class="">
</div>
<div class="">Verifier checks that an overloaded intrinsic name matches with its signature.</div>
<div class=""><br class="">
</div>
<div class="">When different modules are loaded in LTO configuration with the same LLVMContext, types with the same name from different modules are renamed so their names are unique (%struct.foobar in the second module becomes %struct.foobar.0). After renaming
 intrinsic names and signatures can become inconsistent.</div>
<div class=""><br class="">
</div>
<div class="">Usually it slips unnoticed because we don't verify individual modules and eventually map isomorphic types to a single type. So isomorphic types get their original names. Although in some cases it causes problems. </div>
<div class=""><br class="">
</div>
<div class="">Initially I came across the problem with my recent change which added an overloaded type to the masked load/store intrinsics (<a href="http://reviews.llvm.org/D17270" class="">http://reviews.llvm.org/D17270</a>). The discrepancy between the name
 and the signature triggers auto-upgrade bit from my patch converting an incorrect mangling to the correct one. But later after remapping of isomorphic types when we return to the original type name this â€œupdated" intrinsic name become invalid.</div>
<div class=""><br class="">
</div>
<div class="">Another way to trigger the problem is to have different types with the same name in different modules. Corresponding test case is attached. In this case types in different modules will be renamed but the intrinsics from different modules will
 have the same name which will be caught by verifier.</div>
<div class=""><br class="">
</div>
<div class="">As a possible solution we can use AutoUpgrade to handle the situation when the name of the intrinsic doesn't match with its signature. In such cases we have to rename the intrinsic. Then during linking if we map some isomorphic types we have to
 update intrinsics names. To do that we have to teach IRMover to update intrinsics signatures according to the types mapping.</div>
<div class=""><br class="">
</div>
<div class="">Does this sound reasonable? Are there any other alternatives?</div>
<div class=""><br class="">
</div>
<div class="">Artur</div>
<div class=""><br class="">
</div>
<div class="">To reproduce:</div>
<div class="">
<div class="">$ clang -O3 -S -march=core-avx2 -emit-llvm bar.c</div>
<div class="">$ clang -O3 -S -march=core-avx2 -emit-llvm foo.c</div>
<div class="">$ llvm-as bar.ll</div>
<div class="">$ llvm-as foo.ll</div>
<div class="">$ llvm-lto foo.bc bar.bc</div>
<div class="">
<div class="">Invalid user of intrinsic instruction!</div>
<div class=""><4 x %struct.foobar.0*> (<4 x %struct.foobar.0*>*, i32, <4 x i1>, <4 x %struct.foobar.0*>)* bitcast (<4 x %struct.foobar*> (<4 x %struct.foobar*>*, i32, <4 x i1>, <4 x %struct.foobar*>)* @llvm.masked.load.v4p0struct.foobar to <4 x %struct.foobar.0*>
 (<4 x %struct.foobar.0*>*, i32, <4 x i1>, <4 x %struct.foobar.0*>)*)</div>
<div class="">Invalid user of intrinsic instruction!</div>
<div class="">void (<4 x %struct.foobar.0*>, <4 x %struct.foobar.0*>*, i32, <4 x i1>)* bitcast (void (<4 x %struct.foobar*>, <4 x %struct.foobar*>*, i32, <4 x i1>)* @llvm.masked.store.v4p0struct.foobar to void (<4 x %struct.foobar.0*>, <4 x %struct.foobar.0*>*,
 i32, <4 x i1>)*)</div>
<div class="">LLVM ERROR: Broken module found, compilation aborted!</div>
</div>
</div>
<div class=""></div>
</div>
<div style="word-wrap:break-word">
<div></div>
</div>
<div class="" style="word-wrap:break-word">
<div class=""></div>
</div>
</body>
</html>