<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I took a quick look at this and relaxed the conditions under which we prevent immediate subsumption (specifically, optsize and instruction shape), and I managed
to merge 2 of those immediates. I need to dig in a little more to see why it didn’t catch the third. I suspect a phase ordering issue.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I’ll take a closer look at this as soon as I get a chance. If you could please attach a testcase to the bug report, I’d appreciate it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Zia.<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><a name="_____replyseparator"></a><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Sanjay Patel [mailto:spatel@rotateright.com]
<br>
<b>Sent:</b> Thursday, February 11, 2016 3:02 PM<br>
<b>To:</b> Nat! <nat@mulle-kybernetik.com><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org>; Ansari, Zia <zia.ansari@intel.com><br>
<b>Subject:</b> Re: [llvm-dev] Expected constant simplification not happening<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">[cc'ing Zia]<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">We have this transform with -Os for some cases after:<br>
<a href="http://reviews.llvm.org/rL244601">http://reviews.llvm.org/rL244601</a><br>
<a href="http://reviews.llvm.org/D11363">http://reviews.llvm.org/D11363</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">but something in this example is causing the transform to not trigger.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">I filed a related bug here:<br>
<a href="https://llvm.org/bugs/show_bug.cgi?id=24448">https://llvm.org/bugs/show_bug.cgi?id=24448</a><o:p></o:p></p>
</div>
<p class="MsoNormal">If you can file your test case(s) in a bug report, that would be the best way to track progress on solving it. Thanks!<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Thu, Feb 11, 2016 at 9:58 AM, Nat! via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Hi<br>
<br>
the appended IR code does not optimize to my liking :)<br>
<br>
this is the interesting part in x86_64, that got produced via clang -Os:<br>
---<br>
movq -16(%r12), %rax<br>
movl -4(%rax), %ecx<br>
andl $2298949, %ecx ## imm = 0x231445<br>
cmpq $2298949, (%rax,%rcx) ## imm = 0x231445<br>
leaq 8(%rax,%rcx), %rax<br>
cmovneq %r15, %rax <br>
movl $2298949, %esi ## imm = 0x231445<br>
movq %r12, %rdi<br>
movq %r14, %rdx<br>
callq *(%rax)<br>
---<br>
<br>
<br>
and clang -O3:<br>
---<br>
movq -16(%r12), %rax<br>
movl -4(%rax), %ecx<br>
andl $2298949, %ecx ## imm = 0x231445<br>
cmpl $2298949, (%rax,%rcx) ## imm = 0x231445<br>
jne LBB1_4<br>
leaq 8(%rax,%rcx), %rax<br>
jmp LBB1_5<br>
.align 4, 0x90<br>
LBB1_4:<br>
movq %r15, %rax<br>
LBB1_5:<br>
movl $2298949, %esi ## imm = 0x231445<br>
movq %r12, %rdi<br>
movq %r14, %rdx<br>
callq *(%rax)<br>
---<br>
<br>
As you can see in both cases the constant $2298949 is replicated 3 times. I would have expected something like the following code at least for -Os:<br>
<br>
---<br>
movq -16(%r12), %rax<br>
movl $2298949, %esi ### **** move on up <br>
movl -4(%rax), %ecx<br>
andl %esi, %ecx ###<br>
cmpl %esi, (%rax,%rcx) ###<br>
leaq 8(%rax,%rcx), %rax<br>
cmovneq %r15, %rax <br>
movq %r12, %rdi<br>
movq %r14, %rdx<br>
callq *(%rax)<br>
---<br>
<br>
It is much shorter (33 bytes vs. 42 bytes) and I would assume at least the same speed or better. This is with llvm 3.7.0. And yes this pains me at the moment :)<br>
<br>
Ciao<br>
Nat!<br>
----<br>
; ModuleID = 'optimize-fail.c'<br>
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
target triple = "x86_64-apple-macosx10.10.0"<br>
<br>
%struct._foo = type {}<br>
%struct._entry = type { i32, i32, i8* (%struct._foo*, i32, i8*)* }<br>
%struct._table = type { i64, i32, i32, [1 x %struct._entry] }<br>
%struct.test = type { %struct.__foo, i32 }<br>
%struct.__foo = type { %struct._dispatch }<br>
%struct._dispatch = type { %struct._entry*, i8* (%struct._foo*, i32, i8*)* }<br>
<br>
@str = private unnamed_addr constant [8 x i8] c"table_f\00"<br>
@str.2 = private unnamed_addr constant [11 x i8] c"dispatch_f\00"<br>
<br>
; Function Attrs: nounwind<br>
declare void @llvm.lifetime.start(i64, i8* nocapture) #1<br>
<br>
; Function Attrs: nounwind<br>
declare void @llvm.lifetime.end(i64, i8* nocapture) #1<br>
<br>
; Function Attrs: noinline nounwind ssp uwtable<br>
define i8* @foo(%struct._foo* %obj, i32 %unused, i8* %value) #2 {<br>
entry:<br>
%tobool.i = icmp eq %struct._foo* %obj, null<br>
%0 = bitcast %struct._foo* %obj to i8*<br>
%arrayidx.i.i = getelementptr inbounds i8, i8* %0, i64 -16<br>
%entries2.i = bitcast i8* %arrayidx.i.i to %struct._entry**<br>
%f7.i = getelementptr inbounds i8, i8* %0, i64 -8<br>
br i1 %tobool.i, label %for.end, label %call.exit.preheader<br>
<br>
call.exit.preheader: ; preds = %entry<br>
br label %call.exit<br>
<br>
call.exit: ; preds = %call.exit.preheader, %call.exit<br>
%i.04 = phi i32 [ %inc, %call.exit ], [ 0, %call.exit.preheader ]<br>
%1 = load %struct._entry*, %struct._entry** %entries2.i, align 8, !tbaa !2<br>
%arrayidx1.i.i = getelementptr inbounds %struct._entry, %struct._entry* %1, i64 -1<br>
%2 = bitcast %struct._entry* %arrayidx1.i.i to %struct._table*<br>
%mask4.i = getelementptr inbounds %struct._table, %struct._table* %2, i64 0, i32 2<br>
%3 = load i32, i32* %mask4.i, align 4, !tbaa !7<br>
%and.i = and i32 %3, 2298949<br>
%idxprom.i = zext i32 %and.i to i64<br>
%4 = bitcast %struct._entry* %1 to i8*<br>
%arrayidx.i = getelementptr inbounds i8, i8* %4, i64 %idxprom.i<br>
%key5.i = bitcast i8* %arrayidx.i to i32*<br>
%5 = load i32, i32* %key5.i, align 4, !tbaa !11<br>
%cmp.i = icmp eq i32 %5, 2298949<br>
%f6.i = getelementptr inbounds i8, i8* %arrayidx.i, i64 8<br>
%cond.in.v.i = select i1 %cmp.i, i8* %f6.i, i8* %f7.i<br>
%cond.in.i = bitcast i8* %cond.in.v.i to i8* (%struct._foo*, i32, i8*)**<br>
%cond.i = load i8* (%struct._foo*, i32, i8*)*, i8* (%struct._foo*, i32, i8*)** %cond.in.i, align 8<br>
%call8.i = tail call i8* %cond.i(%struct._foo* %obj, i32 2298949, i8* %value) #1<br>
%inc = add nuw nsw i32 %i.04, 1<br>
%exitcond = icmp eq i32 %inc, 100<br>
br i1 %exitcond, label %for.end.loopexit, label %call.exit<br>
<br>
for.end.loopexit: ; preds = %call.exit<br>
%call8.i.lcssa = phi i8* [ %call8.i, %call.exit ]<br>
br label %for.end<br>
<br>
for.end: ; preds = %for.end.loopexit, %entry<br>
%rval.0.lcssa = phi i8* [ %0, %entry ], [ %call8.i.lcssa, %for.end.loopexit ]<br>
ret i8* %rval.0.lcssa<br>
}<br>
<br>
<br>
attributes #1 = { nounwind }<br>
attributes #2 = { noinline nounwind ssp uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="core2"
"target-features"="+cx16,+sse,+sse2,+sse3,+ssse3" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
<br>
!llvm.module.flags = !{!0}<br>
!llvm.ident = !{!1}<br>
<br>
---<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>