<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Re-applied as <span style="font-family: Menlo; font-size: 11px;" class="">Committed revision 260612.</span><div style=""><blockquote type="cite" class=""><div class="">On Feb 9, 2016, at 11:34 AM, Quentin Colombet <<a href="mailto:qcolombet@apple.com" class="">qcolombet@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Actually, that was the only problem.<div class="">A clean build of clang and LTO with a hacky fix fixes the stage2 build even with that patch in.</div><div class=""><br class=""></div><div class="">Anyhow, I think we need to wait for this PR to be fixed before reapplying this patch.</div><div class="">Note, the reason why it was not failing before that patch is because the basic alias analysis was able to correctly answer in the cases we were interested, because it found the underlying object through the bitcasts. Now, with the ptrtoint or inttoptr in the way, the basic alias analysis failed to find a definite answer and relied on TBAA to give the right answer. The TBAA information were wrong all the time (the involved files are regexec.c and Regex.cpp).</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">-Quentin</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 9, 2016, at 9:59 AM, Quentin Colombet <<a href="mailto:qcolombet@apple.com" class="">qcolombet@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Part of the problem is <a href="https://llvm.org/bugs/show_bug.cgi?id=26550" class="">https://llvm.org/bugs/show_bug.cgi?id=26550</a>.<div class="">It seems there are other problems as well, I am still investigating.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Q.<br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 3, 2016, at 10:33 AM, Quentin Colombet <<a href="mailto:qcolombet@apple.com" class="">qcolombet@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">For the record, I think it has to do with type based alias analysis.<div class=""><br class=""></div><div class="">Q.<br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 3, 2016, at 10:15 AM, Quentin Colombet via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">+llvm-commit<br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 3, 2016, at 10:14 AM, Quentin Colombet <<a href="mailto:qcolombet@apple.com" class="">qcolombet@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi David,<div class=""><br class=""></div><div class="">Sorry to bring that commit up, but I’ve reverted it in <span style="font-family: 'Helvetica Neue';" class="">r259674.</span></div><div class=""><font face="Helvetica Neue" class="">According to git bisect, this is the root cause of a miscompile in Regex.</font></div><div class=""><font face="Helvetica Neue" class="">I’ve put the detailed on how to reproduce in the commit message of </font><span style="font-family: 'Helvetica Neue';" class="">r259674.</span></div><div class=""><font face="Helvetica Neue" class=""><br class=""></font></div><div class=""><font face="Helvetica Neue" class="">I am working on reducing the test case (which right now is a bootstrap, then build llvm-extract with lto).</font></div><div class=""><font face="Helvetica Neue" class=""><br class=""></font></div><div class=""><font face="Helvetica Neue" class="">I am guessing that the bug is not actually in this commit but exposes more opportunities to another optimization to go wrong.</font></div><div class=""><br class=""></div><div class="">Anyhow, I’ve reverted it, because we have some internal bots that hit this now.</div><div class=""><br class=""></div><div class=""><font face="Helvetica Neue" class="">Thanks,</font></div><div class=""><font face="Helvetica Neue" class="">-Quentin</font></div><div class=""><font face="Helvetica Neue" class=""><br class=""></font><div class=""><blockquote type="cite" class=""><div class="">On May 28, 2015, at 11:52 AM, David Majnemer <<a href="mailto:david.majnemer@gmail.com" class="">david.majnemer@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Patch by Philip Pfaffe!</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, May 28, 2015 at 11:39 AM, David Majnemer <span dir="ltr" class=""><<a href="mailto:david.majnemer@gmail.com" target="_blank" class="">david.majnemer@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: majnemer<br class="">
Date: Thu May 28 13:39:17 2015<br class="">
New Revision: 238452<br class="">
<br class="">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D238452-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=olNjq2h6jOqNEfp-gkn0gkdSmC_Cq2PIHP67QCufkSY&s=sY9wqRVuCtMcwCgMuzhFlmNBzaeMHGzxurg-FS2sE_w&e=" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=238452&view=rev</a><br class="">
Log:<br class="">
[InstCombine] Fold IntToPtr and PtrToInt into preceding loads.<br class="">
<br class="">
Currently we only fold a BitCast into a Load when the BitCast is its<br class="">
only user.<br class="">
<br class="">
Do the same for any no-op cast.<br class="">
<br class="">
Differential Revision: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D9152&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=olNjq2h6jOqNEfp-gkn0gkdSmC_Cq2PIHP67QCufkSY&s=0ErPMlQC5TI1p-lxa0ZTYmfyih7fQVsAo9kgeBsBiLo&e=" target="_blank" class="">http://reviews.llvm.org/D9152</a><br class="">
<br class="">
Added:<br class="">
llvm/trunk/test/Transforms/InstCombine/load-bitcast32.ll<br class="">
llvm/trunk/test/Transforms/InstCombine/load-bitcast64.ll<br class="">
Modified:<br class="">
llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp<br class="">
<br class="">
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp<br class="">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Transforms_InstCombine_InstCombineLoadStoreAlloca.cpp-3Frev-3D238452-26r1-3D238451-26r2-3D238452-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=olNjq2h6jOqNEfp-gkn0gkdSmC_Cq2PIHP67QCufkSY&s=QM30wzxtVasww-Km95KLdBoCNDt_25E5FeFDPrMWQp4&e=" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=238452&r1=238451&r2=238452&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)<br class="">
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Thu May 28 13:39:17 2015<br class="">
@@ -483,12 +483,17 @@ static Instruction *combineLoadToOperati<br class="">
}<br class="">
<br class="">
// Fold away bit casts of the loaded value by loading the desired type.<br class="">
+ // We can do this for BitCastInsts as well as casts from and to pointer types,<br class="">
+ // as long as those are noops (i.e., the source or dest type have the same<br class="">
+ // bitwidth as the target's pointers).<br class="">
if (LI.hasOneUse())<br class="">
- if (auto *BC = dyn_cast<BitCastInst>(LI.user_back())) {<br class="">
- LoadInst *NewLoad = combineLoadToNewType(IC, LI, BC->getDestTy());<br class="">
- BC->replaceAllUsesWith(NewLoad);<br class="">
- IC.EraseInstFromFunction(*BC);<br class="">
- return &LI;<br class="">
+ if (auto* CI = dyn_cast<CastInst>(LI.user_back())) {<br class="">
+ if (CI->isNoopCast(DL)) {<br class="">
+ LoadInst *NewLoad = combineLoadToNewType(IC, LI, CI->getDestTy());<br class="">
+ CI->replaceAllUsesWith(NewLoad);<br class="">
+ IC.EraseInstFromFunction(*CI);<br class="">
+ return &LI;<br class="">
+ }<br class="">
}<br class="">
<br class="">
// FIXME: We should also canonicalize loads of vectors when their elements are<br class="">
<br class="">
Added: llvm/trunk/test/Transforms/InstCombine/load-bitcast32.ll<br class="">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_Transforms_InstCombine_load-2Dbitcast32.ll-3Frev-3D238452-26view-3Dauto&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=olNjq2h6jOqNEfp-gkn0gkdSmC_Cq2PIHP67QCufkSY&s=NrPn-jA9V0ieNNsVOi8wYa31xU_WEeNqb6Qk8C4cnJA&e=" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/load-bitcast32.ll?rev=238452&view=auto</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/test/Transforms/InstCombine/load-bitcast32.ll (added)<br class="">
+++ llvm/trunk/test/Transforms/InstCombine/load-bitcast32.ll Thu May 28 13:39:17 2015<br class="">
@@ -0,0 +1,79 @@<br class="">
+; RUN: opt -instcombine -S < %s | FileCheck %s<br class="">
+<br class="">
+target datalayout = "p:32:32:32"<br class="">
+<br class="">
+<br class="">
+define i64* @test1(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test1(<br class="">
+; CHECK: load i64, i64*<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i64*<br class="">
+ %b = load i64, i64* %a<br class="">
+ %c = inttoptr i64 %b to i64*<br class="">
+<br class="">
+ ret i64* %c<br class="">
+}<br class="">
+<br class="">
+define i32* @test2(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test2(<br class="">
+; CHECK: load i32*, i32**<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i32*<br class="">
+ %b = load i32, i32* %a<br class="">
+ %c = inttoptr i32 %b to i32*<br class="">
+<br class="">
+ ret i32* %c<br class="">
+}<br class="">
+<br class="">
+define i64* @test3(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test3(<br class="">
+; CHECK: load i64*, i64**<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i32*<br class="">
+ %b = load i32, i32* %a<br class="">
+ %c = inttoptr i32 %b to i64*<br class="">
+<br class="">
+ ret i64* %c<br class="">
+}<br class="">
+<br class="">
+define i64 @test4(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test4(<br class="">
+; CHECK: load i32, i32*<br class="">
+; CHECK: zext<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i64**<br class="">
+ %b = load i64*, i64** %a<br class="">
+ %c = ptrtoint i64* %b to i64<br class="">
+<br class="">
+ ret i64 %c<br class="">
+}<br class="">
+<br class="">
+define i32 @test5(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test5(<br class="">
+; CHECK: load i32, i32*<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i32**<br class="">
+ %b = load i32*, i32** %a<br class="">
+ %c = ptrtoint i32* %b to i32<br class="">
+<br class="">
+ ret i32 %c<br class="">
+}<br class="">
+<br class="">
+define i64 @test6(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test6(<br class="">
+; CHECK: load i32, i32*<br class="">
+; CHECK: zext<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i32**<br class="">
+ %b = load i32*, i32** %a<br class="">
+ %c = ptrtoint i32* %b to i64<br class="">
+<br class="">
+ ret i64 %c<br class="">
+}<br class="">
+<br class="">
<br class="">
Added: llvm/trunk/test/Transforms/InstCombine/load-bitcast64.ll<br class="">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_Transforms_InstCombine_load-2Dbitcast64.ll-3Frev-3D238452-26view-3Dauto&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=olNjq2h6jOqNEfp-gkn0gkdSmC_Cq2PIHP67QCufkSY&s=Ct7qAC1oyddLnff8X5WXL8bZlU4kgWSD4P7ZT45sFt8&e=" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/load-bitcast64.ll?rev=238452&view=auto</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/test/Transforms/InstCombine/load-bitcast64.ll (added)<br class="">
+++ llvm/trunk/test/Transforms/InstCombine/load-bitcast64.ll Thu May 28 13:39:17 2015<br class="">
@@ -0,0 +1,78 @@<br class="">
+; RUN: opt -instcombine -S < %s | FileCheck %s<br class="">
+<br class="">
+target datalayout = "p:64:64:64"<br class="">
+<br class="">
+<br class="">
+define i64* @test1(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test1(<br class="">
+; CHECK: load i64*, i64**<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i64*<br class="">
+ %b = load i64, i64* %a<br class="">
+ %c = inttoptr i64 %b to i64*<br class="">
+<br class="">
+ ret i64* %c<br class="">
+}<br class="">
+<br class="">
+define i32* @test2(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test2(<br class="">
+; CHECK: load i32, i32*<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i32*<br class="">
+ %b = load i32, i32* %a<br class="">
+ %c = inttoptr i32 %b to i32*<br class="">
+<br class="">
+ ret i32* %c<br class="">
+}<br class="">
+<br class="">
+define i64* @test3(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test3(<br class="">
+; CHECK: load i32, i32*<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i32*<br class="">
+ %b = load i32, i32* %a<br class="">
+ %c = inttoptr i32 %b to i64*<br class="">
+<br class="">
+ ret i64* %c<br class="">
+}<br class="">
+<br class="">
+define i64 @test4(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test4(<br class="">
+; CHECK: load i64, i64*<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i64**<br class="">
+ %b = load i64*, i64** %a<br class="">
+ %c = ptrtoint i64* %b to i64<br class="">
+<br class="">
+ ret i64 %c<br class="">
+}<br class="">
+<br class="">
+define i32 @test5(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test5(<br class="">
+; CHECK: load i64, i64*<br class="">
+; CHECK: trunc<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i32**<br class="">
+ %b = load i32*, i32** %a<br class="">
+ %c = ptrtoint i32* %b to i32<br class="">
+<br class="">
+ ret i32 %c<br class="">
+}<br class="">
+<br class="">
+define i64 @test6(i8* %x) {<br class="">
+entry:<br class="">
+; CHECK-LABEL: @test6(<br class="">
+; CHECK: load i64, i64*<br class="">
+; CHECK: ret<br class="">
+ %a = bitcast i8* %x to i32**<br class="">
+ %b = load i32*, i32** %a<br class="">
+ %c = ptrtoint i32* %b to i64<br class="">
+<br class="">
+ ret i64 %c<br class="">
+}<br class="">
+<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div><br class=""></div>
_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div>_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>