<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p>Hello Haicheng,<br>
</p>
<br>
I have cross-compiled according to your instructions (replacing the gcc toolchain by the latest one from Linaro) and linking with gold.<span> I ran ./scimark2 and everything works fine. I have also tried with flag "-large" but after leaving it for 15 hours,
I have killed it (it behaves the same without my patches). What is the command you use to<span> run the benchmark? Do you use some other flag?<br>
<br>
Thanks,<br>
Pablo<br>
</span></span><br>
<div style="color: rgb(0, 0, 0);">
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> haicheng@codeaurora.org <haicheng@codeaurora.org><br>
<b>Sent:</b> 23 November 2016 03:49<br>
<b>To:</b> Pablo Barrio<br>
<b>Cc:</b> mcrosier@codeaurora.org; llvm-commits@lists.llvm.org; nd<br>
<b>Subject:</b> Re: [llvm] r286236 - [JumpThreading] Unfold selects that depend on the same condition</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Hi Pablo,<br>
<br>
Thank you for looking at this. I tried ToT with your two patches again <br>
today. They still fail on qemu and on real device.<br>
<br>
We don't use lnt. We cross-compile. The compilation commands generated <br>
by our infrastructure are<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/LU.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/LU.c<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/FFT.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/FFT.c<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/array.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/array.c<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/Stopwatch.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/Stopwatch.c<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/Random.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/Random.c<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/SparseCompRow.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/SparseCompRow.c<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/MonteCarlo.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/MonteCarlo.c<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/kernel.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/kernel.c<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/scimark2.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/scimark2.c<br>
<br>
clang-aarch64-x -DNDEBUG <br>
-I/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C
<br>
-I/local/mnt/workspace/scratch/haicheng/test_2016-11-22_22-28-03.429027/llvm-test-suite/cmakebuild/MultiSource/Benchmarks/SciMark2-C
<br>
-O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -w -Werror=date-time -o <br>
CMakeFiles/scimark2.dir/SOR.c.o -c <br>
/local/mnt/workspace/llvm-rtp-build-infra/benchmark-src/llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/SOR.c<br>
<br>
clang-aarch64-x -O3 -flto -fuse-ld=gold -mcpu=cortex-a57 -O3 -flto <br>
-fuse-ld=gold -mcpu=cortex-a57 -static CMakeFiles/scimark2.dir/LU.c.o <br>
CMakeFiles/scimark2.dir/FFT.c.o CMakeFiles/scimark2.dir/array.c.o <br>
CMakeFiles/scimark2.dir/Stopwatch.c.o CMakeFiles/scimark2.dir/Random.c.o <br>
CMakeFiles/scimark2.dir/SparseCompRow.c.o <br>
CMakeFiles/scimark2.dir/MonteCarlo.c.o <br>
CMakeFiles/scimark2.dir/kernel.c.o CMakeFiles/scimark2.dir/scimark2.c.o <br>
CMakeFiles/scimark2.dir/SOR.c.o -o scimark2 -lm<br>
<br>
clang-aarch64-x is a wrapper of following flags<br>
<br>
clang --target=aarch64-linux-gnu <br>
--sysroot=/local/mnt/workspace/llvm-rtp-build-infra/sysroots/gcc-fsf-aarch64-linux-gnu-6.1.0/aarch64-linux-gnu/libc
<br>
-isystem <br>
/local/mnt/workspace/llvm-rtp-build-infra/sysroots/gcc-fsf-aarch64-linux-gnu-6.1.0/aarch64-linux-gnu/include/c++/6.1.0
<br>
-isystem <br>
/local/mnt/workspace/llvm-rtp-build-infra/sysroots/gcc-fsf-aarch64-linux-gnu-6.1.0/aarch64-linux-gnu/include/c++/6.1.0/aarch64-linux-gnu
<br>
-isystem <br>
/local/mnt/workspace/llvm-rtp-build-infra/sysroots/gcc-fsf-aarch64-linux-gnu-6.1.0/aarch64-linux-gnu/include/c++/6.1.0/backward
<br>
--gcc-toolchain=/local/mnt/workspace/llvm-rtp-build-infra/sysroots/gcc-fsf-aarch64-linux-gnu-6.1.0<br>
<br>
Best,<br>
<br>
Haicheng<br>
<br>
On 2016-11-22 08:48, Pablo Barrio wrote:<br>
> Hello Haicheng,<br>
> <br>
> I have been trying to reproduce the issue but it is working fine for<br>
> me. I have run the LLVM test suite with the following command:<br>
> <br>
> lnt runtest nt --no-timestamp --sandbox venv-llvm-tools --test-suite<br>
> llvm-test-suite --cc /work/llvm-patched/bin/clang --cxx<br>
> /work/llvm-patched/bin/clang++ --cflag -mcpu=cortex-a57 --cflag -O3<br>
> --cflag -flto --cflag -fuse-ld=gold --threads=8 --build-threads=8<br>
> --verbose<br>
> <br>
> llvm-patched is a compiler built from top-of-tree with my two patches<br>
> on top. I am compiling and running natively on a Cortex-A57.<br>
> <br>
> Could you share the exact commands that you use for reproducing the<br>
> issue? Do you run SciMark2 through lnt or do you invoke the benchmark<br>
> directly? Are you cross-compiling? Any extra information you can give<br>
> may be of help.<br>
> <br>
> Many thanks,<br>
> <br>
> Pablo<br>
> <br>
> -------------------------<br>
> <br>
> FROM: Haicheng Wu <haicheng@codeaurora.org><br>
> SENT: 15 November 2016 21:01<br>
> TO: Pablo Barrio; mcrosier@codeaurora.org<br>
> CC: llvm-commits@lists.llvm.org<br>
> SUBJECT: RE: [llvm] r286236 - [JumpThreading] Unfold selects that<br>
> depend on the same condition<br>
> <br>
> Hi Pablo,<br>
> <br>
> Thank you for doing this.<br>
> <br>
> I also take another look at your patch. I think you may only need to<br>
> unfold selects belonging to the same basic block. If they are in two<br>
> different blocks, my understanding is that current jumpthreading<br>
> implementation does not have the capability of optimizing the unfolded<br>
> blocks without something like <a href="https://reviews.llvm.org/D22779">https://reviews.llvm.org/D22779</a>.<br>
> <br>
> Best,<br>
> <br>
> Haicheng Wu<br>
> <br>
> Employee of Qualcomm Datacenter Technologies, Inc.<br>
> <br>
> Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm<br>
> Technologies, Inc. Qualcomm Technologies, Inc. is a member of the<br>
> Code Aurora Forum, a Linux Foundation Collaborative Project.<br>
> <br>
> FROM: Pablo Barrio [<a href="mailto:Pablo.Barrio@arm.com">mailto:Pablo.Barrio@arm.com</a>]<br>
> SENT: Tuesday, November 15, 2016 10:15 AM<br>
> TO: mcrosier@codeaurora.org<br>
> CC: haicheng@codeaurora.org; llvm-commits@lists.llvm.org<br>
> SUBJECT: Re: [llvm] r286236 - [JumpThreading] Unfold selects that<br>
> depend on the same condition<br>
> <br>
> Sure, I'll revert now.<br>
> <br>
> -------------------------<br>
> <br>
> FROM: mcrosier@codeaurora.org <mcrosier@codeaurora.org><br>
> SENT: 15 November 2016 14:18:20<br>
> TO: Pablo Barrio<br>
> CC: haicheng@codeaurora.org; llvm-commits@lists.llvm.org<br>
> SUBJECT: Re: [llvm] r286236 - [JumpThreading] Unfold selects that<br>
> depend on the same condition<br>
> <br>
> Hi Pablo,<br>
> Thanks for taking a look at this. If you don't think you'll have a<br>
> fix<br>
> in the very near future would you mind reverting your commit while you<br>
> <br>
> investigate?<br>
> <br>
> Chad<br>
> <br>
> On 2016-11-15 05:44, Pablo Barrio via llvm-commits wrote:<br>
>> Thank you Hai, I will have a look at it now.<br>
>> <br>
>> Pablo<br>
>> <br>
>> -------------------------<br>
>> <br>
>> FROM: haicheng@codeaurora.org <haicheng@codeaurora.org><br>
>> SENT: 15 November 2016 03:24:37<br>
>> TO: Pablo Barrio<br>
>> CC: llvm-commits@lists.llvm.org<br>
>> SUBJECT: RE: [llvm] r286236 - [JumpThreading] Unfold selects that<br>
>> depend on the same condition<br>
>> <br>
>> Hi Pablo,<br>
>> <br>
>> It seems that your jumpthreading patch r286236 miscompiles<br>
>> llvm-test-suite/MultiSource/Benchmarks/SciMark2-C/scimark2 when<br>
> using<br>
>> O3+LTO<br>
>> and running on AArch64.<br>
>> <br>
>> Here is the flag I used to compile " -O3 -flto -fuse-ld=gold<br>
>> -mcpu=cortex-a57"<br>
>> I used normal input size and got seg fault. Small input size seems<br>
>> okay.<br>
>> <br>
>> Please let me know if you need more information.<br>
>> <br>
>> Haicheng Wu<br>
>> Employee of Qualcomm Datacenter Technologies, Inc.<br>
>> Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm<br>
>> Technologies, Inc. Qualcomm Technologies, Inc. is a member of the<br>
>> Code<br>
>> Aurora Forum, a Linux Foundation Collaborative Project.<br>
>> <br>
>> -----Original Message-----<br>
>> From: llvm-commits [<a href="mailto:llvm-commits-bounces@lists.llvm.org">mailto:llvm-commits-bounces@lists.llvm.org</a>] On<br>
>> Behalf Of<br>
>> Pablo Barrio via llvm-commits<br>
>> Sent: Tuesday, November 08, 2016 9:54 AM<br>
>> To: llvm-commits@lists.llvm.org<br>
>> Subject: [llvm] r286236 - [JumpThreading] Unfold selects that depend<br>
>> on<br>
>> the<br>
>> same condition<br>
>> <br>
>> Author: pabbar01<br>
>> Date: Tue Nov 8 08:53:30 2016<br>
>> New Revision: 286236<br>
>> <br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=286236&view=rev">http://llvm.org/viewvc/llvm-project?rev=286236&view=rev</a> [1]<br>
>> Log:<br>
>> [JumpThreading] Unfold selects that depend on the same condition<br>
>> <br>
>> Summary:<br>
>> These are good candidates for jump threading. This enables later<br>
> opts<br>
>> (such<br>
>> as InstCombine) to combine instructions from the selects with<br>
>> instructions<br>
>> out of the selects. SimplifyCFG will fold the select again if<br>
>> unfolding<br>
>> wasn't worth it.<br>
>> <br>
>> Patch by James Molloy and Pablo Barrio.<br>
>> <br>
>> Reviewers: rengolin, haicheng, sebpop<br>
>> <br>
>> Subscribers: jojo, jmolloy, llvm-commits<br>
>> <br>
>> Differential Revision: <a href="https://reviews.llvm.org/D26391">https://reviews.llvm.org/D26391</a> [2]<br>
>> <br>
>> Added:<br>
>> <br>
>> llvm/trunk/test/Transforms/JumpThreading/unfold-selects-same-cond.ll<br>
>> Modified:<br>
>> llvm/trunk/include/llvm/Transforms/Scalar/JumpThreading.h<br>
>> llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp<br>
>> <br>
>> Modified: llvm/trunk/include/llvm/Transforms/Scalar/JumpThreading.h<br>
>> URL:<br>
>> <br>
> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/JumpThreading.h?rev=286236&r1=286235&r2=286236&view=diff">
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/JumpThreading.h?rev=286236&r1=286235&r2=286236&view=diff</a><br>
> [3]<br>
>> <br>
> ==============================================================================<br>
>> --- llvm/trunk/include/llvm/Transforms/Scalar/JumpThreading.h<br>
>> (original)<br>
>> +++ llvm/trunk/include/llvm/Transforms/Scalar/JumpThreading.h Tue<br>
> Nov<br>
>> 8<br>
>> +++ 08:53:30 2016<br>
>> @@ -129,6 +129,8 @@ private:<br>
>> BasicBlock *NewBB, BasicBlock<br>
>> *SuccBB);<br>
>> /// Check if the block has profile metadata for its outgoing<br>
>> edges.<br>
>> bool doesBlockHaveProfileData(BasicBlock *BB);<br>
>> + SelectInst *getSelectFedByPhi(PHINode *PN); void<br>
>> + expandSelect(SelectInst *SI);<br>
>> };<br>
>> <br>
>> } // end namespace llvm<br>
>> <br>
>> Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp<br>
>> URL:<br>
>> <br>
> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=286236&r1=286235&r2=286236&view=diff">
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=286236&r1=286235&r2=286236&view=diff</a><br>
> [4]<br>
>> <br>
> ==============================================================================<br>
>> --- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)<br>
>> +++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Tue Nov 8<br>
>> +++ 08:53:30 2016<br>
>> @@ -1963,61 +1963,100 @@ bool JumpThreadingPass::TryToUnfoldSelec<br>
>> return false;<br>
>> }<br>
>> <br>
>> -/// TryToUnfoldSelectInCurrBB - Look for PHI/Select in the same BB<br>
> of<br>
>> <br>
>> the<br>
>> form<br>
>> +/// GetSelectFedByPhi - Look for PHI/Select in the same BB of the<br>
>> form<br>
>> /// bb:<br>
>> /// %p = phi [false, %bb1], [true, %bb2], [false, %bb3], [true,<br>
>> %bb4],<br>
>> ...<br>
>> /// %s = select p, trueval, falseval<br>
>> ///<br>
>> -/// And expand the select into a branch structure. This later<br>
> enables<br>
>> +/// And return the select. Unfolding it into a branch structure<br>
> later<br>
>> +enables<br>
>> /// jump-threading over bb in this pass.<br>
>> ///<br>
>> -/// Using the similar approach of<br>
> SimplifyCFG::FoldCondBranchOnPHI(),<br>
>> unfold -/// select if the associated PHI has at least one constant.<br>
>> If<br>
>> the<br>
>> unfolded -/// select is not jump-threaded, it will be folded again<br>
> in<br>
>> the<br>
>> later -/// optimizations.<br>
>> +/// Using the similar approach of<br>
> SimplifyCFG::FoldCondBranchOnPHI(),<br>
>> +return /// select if the associated PHI has at least one constant.<br>
>> +SelectInst *JumpThreadingPass::getSelectFedByPhi(PHINode *PN) {<br>
>> +<br>
>> + unsigned NumPHIValues = PN->getNumIncomingValues(); if<br>
>> (NumPHIValues<br>
>> + == 0 || !PN->hasOneUse())<br>
>> + return nullptr;<br>
>> +<br>
>> + SelectInst *SI = dyn_cast<SelectInst>(PN->user_back());<br>
>> + BasicBlock *BB = PN->getParent();<br>
>> + if (!SI || SI->getParent() != BB)<br>
>> + return nullptr;<br>
>> +<br>
>> + Value *Cond = SI->getCondition();<br>
>> + if (!Cond || Cond != PN || !Cond->getType()->isIntegerTy(1))<br>
>> + return nullptr;<br>
>> +<br>
>> + for (unsigned i = 0; i != NumPHIValues; ++i) {<br>
>> + if (PN->getIncomingBlock(i) == BB)<br>
>> + return nullptr;<br>
>> + if (isa<ConstantInt>(PN->getIncomingValue(i)))<br>
>> + return SI;<br>
>> + }<br>
>> +<br>
>> + return nullptr;<br>
>> +}<br>
>> +<br>
>> +/// ExpandSelect - Expand a select into an if-then-else construct.<br>
>> +void JumpThreadingPass::expandSelect(SelectInst *SI) {<br>
>> +<br>
>> + BasicBlock *BB = SI->getParent();<br>
>> + TerminatorInst *Term =<br>
>> + SplitBlockAndInsertIfThen(SI->getCondition(), SI, false);<br>
>> + PHINode *NewPN = PHINode::Create(SI->getType(), 2, "", SI);<br>
>> + NewPN->addIncoming(SI->getTrueValue(), Term->getParent());<br>
>> + NewPN->addIncoming(SI->getFalseValue(), BB);<br>
>> + SI->replaceAllUsesWith(NewPN);<br>
>> + SI->eraseFromParent();<br>
>> +}<br>
>> +<br>
>> +/// TryToUnfoldSelectInCurrBB - Unfold selects that could be<br>
>> +jump-threaded were /// they if-then-elses. If the unfolded selects<br>
>> are<br>
>> +not jump-threaded, it will /// be folded again in the later<br>
>> optimizations.<br>
>> bool JumpThreadingPass::TryToUnfoldSelectInCurrBB(BasicBlock *BB)<br>
> {<br>
>> +<br>
>> // If threading this would thread across a loop header, don't<br>
>> thread<br>
>> the<br>
>> edge.<br>
>> // See the comments above FindLoopHeaders for justifications and<br>
>> caveats.<br>
>> if (LoopHeaders.count(BB))<br>
>> return false;<br>
>> <br>
>> - // Look for a Phi/Select pair in the same basic block. The Phi<br>
>> feeds<br>
>> the<br>
>> - // condition of the Select and at least one of the incoming<br>
> values<br>
>> is<br>
>> a<br>
>> - // constant.<br>
>> - for (BasicBlock::iterator BI = BB->begin();<br>
>> - PHINode *PN = dyn_cast<PHINode>(BI); ++BI) {<br>
>> - unsigned NumPHIValues = PN->getNumIncomingValues();<br>
>> - if (NumPHIValues == 0 || !PN->hasOneUse())<br>
>> - continue;<br>
>> + bool Changed = false;<br>
>> + for (auto &I : *BB) {<br>
>> <br>
>> - SelectInst *SI = dyn_cast<SelectInst>(PN->user_back());<br>
>> - if (!SI || SI->getParent() != BB)<br>
>> + // Look for a Phi/Select pair in the same basic block. The Phi<br>
>> feeds<br>
>> the<br>
>> + // condition of the Select and at least one of the incoming<br>
>> values<br>
>> is a<br>
>> + // constant.<br>
>> + PHINode *PN;<br>
>> + SelectInst *SI;<br>
>> + if ((PN = dyn_cast<PHINode>(&I)) && (SI =<br>
> getSelectFedByPhi(PN)))<br>
>> {<br>
>> + expandSelect(SI);<br>
>> + Changed = true;<br>
>> continue;<br>
>> + }<br>
>> <br>
>> - Value *Cond = SI->getCondition();<br>
>> - if (!Cond || Cond != PN || !Cond->getType()->isIntegerTy(1))<br>
>> - continue;<br>
>> + if (I.getType()->isIntegerTy(1)) {<br>
>> <br>
>> - bool HasConst = false;<br>
>> - for (unsigned i = 0; i != NumPHIValues; ++i) {<br>
>> - if (PN->getIncomingBlock(i) == BB)<br>
>> - return false;<br>
>> - if (isa<ConstantInt>(PN->getIncomingValue(i)))<br>
>> - HasConst = true;<br>
>> - }<br>
>> + SmallVector<SelectInst *, 4> Selects;<br>
>> <br>
>> - if (HasConst) {<br>
>> - // Expand the select.<br>
>> - TerminatorInst *Term =<br>
>> - SplitBlockAndInsertIfThen(SI->getCondition(), SI, false);<br>
>> - PHINode *NewPN = PHINode::Create(SI->getType(), 2, "", SI);<br>
>> - NewPN->addIncoming(SI->getTrueValue(), Term->getParent());<br>
>> - NewPN->addIncoming(SI->getFalseValue(), BB);<br>
>> - SI->replaceAllUsesWith(NewPN);<br>
>> - SI->eraseFromParent();<br>
>> - return true;<br>
>> + // Look for scalar booleans used in selects as conditions. If<br>
>> there<br>
>> are<br>
>> + // several selects that use the same boolean, they are<br>
>> candidates<br>
>> for<br>
>> jump<br>
>> + // threading and therefore we should unfold them.<br>
>> + for (Value *U : I.users())<br>
>> + if (auto *SI = dyn_cast<SelectInst>(U))<br>
>> + Selects.push_back(SI);<br>
>> + if (Selects.size() <= 1)<br>
>> + continue;<br>
>> +<br>
>> + // Remove duplicates<br>
>> + std::sort(Selects.begin(), Selects.end());<br>
>> + auto NewEnd = std::unique(Selects.begin(), Selects.end());<br>
>> +<br>
>> + Changed = true;<br>
>> + for (auto SI = Selects.begin(); SI != NewEnd; ++SI)<br>
>> + expandSelect(*SI);<br>
>> }<br>
>> }<br>
>> -<br>
>> - return false;<br>
>> +<br>
>> + return Changed;<br>
>> }<br>
>> <br>
>> Added:<br>
>> llvm/trunk/test/Transforms/JumpThreading/unfold-selects-same-cond.ll<br>
>> URL:<br>
>> <br>
> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/unfold-selects-same-cond.ll?rev=286236&view=auto">
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/unfold-selects-same-cond.ll?rev=286236&view=auto</a><br>
> [5]<br>
>> <br>
> ==============================================================================<br>
>> ---<br>
>> llvm/trunk/test/Transforms/JumpThreading/unfold-selects-same-cond.ll<br>
>> (added)<br>
>> +++<br>
>> llvm/trunk/test/Transforms/JumpThreading/unfold-selects-same-cond.ll<br>
>> +++ Tue Nov 8 08:53:30 2016<br>
>> @@ -0,0 +1,45 @@<br>
>> +; RUN: opt < %s -jump-threading -instcombine -simplifycfg -S |<br>
>> +FileCheck %s<br>
>> +<br>
>> +; The three selects are jump-threaded so that instcombine can<br>
>> optimize,<br>
>> +and ; simplifycfg should turn the result into a single select.<br>
>> +define i32 @f(i32 %a, i32 %b) {<br>
>> +; CHECK: select<br>
>> +; CHECK-NOT: select<br>
>> +entry:<br>
>> + %0 = and i32 %a, 1<br>
>> + %1 = and i32 %b, 1<br>
>> + %xor = xor i32 %1, %a<br>
>> + %shr32 = lshr i32 %a, 1<br>
>> + %cmp10 = icmp eq i32 %xor, 1<br>
>> + %2 = xor i32 %b, 12345<br>
>> + %b.addr.1 = select i1 %cmp10, i32 %2, i32 %b<br>
>> + %shr1633 = lshr i32 %b.addr.1, 1<br>
>> + %3 = or i32 %shr1633, 54321<br>
>> + %b.addr.2 = select i1 %cmp10, i32 %3, i32 %shr1633<br>
>> + %shr1634 = lshr i32 %b.addr.2, 2<br>
>> + %4 = or i32 %shr1634, 54320<br>
>> + %b.addr.3 = select i1 %cmp10, i32 %4, i32 %shr1634<br>
>> + ret i32 %b.addr.3<br>
>> +}<br>
>> +<br>
>> +; Case where the condition is not only used as condition but also<br>
> as<br>
>> +the ; true or false value in at least one of the selects.<br>
>> +define i1 @g(i32 %a, i32 %b) {<br>
>> +; CHECK: select<br>
>> +; CHECK-NOT: select<br>
>> +entry:<br>
>> + %0 = and i32 %a, 1<br>
>> + %1 = and i32 %b, 1<br>
>> + %xor = xor i32 %1, %a<br>
>> + %shr32 = lshr i32 %a, 1<br>
>> + %cmp10 = icmp eq i32 %xor, 1<br>
>> + %2 = xor i32 %b, 12345<br>
>> + %b.addr.1 = select i1 %cmp10, i32 %2, i32 %b<br>
>> + %shr1633 = lshr i32 %b.addr.1, 1<br>
>> + %3 = or i32 %shr1633, 54321<br>
>> + %b.addr.2 = select i1 %cmp10, i32 %3, i32 %shr1633<br>
>> + %shr1634 = lshr i32 %b.addr.2, 2<br>
>> + %4 = icmp eq i32 %shr1634, 54320<br>
>> + %b.addr.3 = select i1 %cmp10, i1 %4, i1 %cmp10<br>
>> + ret i1 %b.addr.3<br>
>> +}<br>
>> <br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> llvm-commits@lists.llvm.org<br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a> [6]<br>
>> IMPORTANT NOTICE: The contents of this email and any attachments<br>
> are<br>
>> confidential and may also be privileged. If you are not the intended<br>
>> recipient, please notify the sender immediately and do not disclose<br>
>> the contents to any other person, use it for any purpose, or store<br>
> or<br>
>> copy the information in any medium. Thank you.<br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> llvm-commits@lists.llvm.org<br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a> [6]<br>
> <br>
> IMPORTANT NOTICE: The contents of this email and any attachments are<br>
> confidential and may also be privileged. If you are not the intended<br>
> recipient, please notify the sender immediately and do not disclose<br>
> the contents to any other person, use it for any purpose, or store or<br>
> copy the information in any medium. Thank you.<br>
> <br>
> Links:<br>
> ------<br>
> [1] <a href="http://llvm.org/viewvc/llvm-project?rev=286236&view=rev">http://llvm.org/viewvc/llvm-project?rev=286236&view=rev</a><br>
> [2] <a href="https://reviews.llvm.org/D26391">https://reviews.llvm.org/D26391</a><br>
> [3]<br>
> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/JumpThreading.h?rev=286236&r1=286235&r2=286236&view=diff">
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/JumpThreading.h?rev=286236&r1=286235&r2=286236&view=diff</a><br>
> [4]<br>
> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=286236&r1=286235&r2=286236&view=diff">
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=286236&r1=286235&r2=286236&view=diff</a><br>
> [5]<br>
> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/unfold-selects-same-cond.ll?rev=286236&view=auto">
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/unfold-selects-same-cond.ll?rev=286236&view=auto</a><br>
> [6] <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</div>
</span></font></div>
</div>
</body>
</html>