https://llvm.org/bugs/show_bug.cgi?id=28439
Bug ID: 28439 Summary: ScalarEvolution creates redundant select from phi Product: libraries Version: trunk Hardware: PC OS: All Status: NEW Severity: normal Priority: P Component: Global Analyses Assignee: unassignedb...@nondot.org Reporter: rmor...@synopsys.com CC: llvm-bugs@lists.llvm.org Classification: Unclassified Created attachment 16699 --> https://llvm.org/bugs/attachment.cgi?id=16699&action=edit C example After http://reviews.llvm.org/D13378 SE can create SCEV expressions from select-like phi nodes. But when such expression is expanded, instead of reusing original phi node, SEExpander creates new select+icmp. This leads to code duplication. Simple example is attached. Use 'clang -O2 -S -emit-llvm test.c' to repoduce. Output with select-like-phi recognition: if.end: ; preds = %if.else, %if.then %N.0 = phi i32 [ %A, %if.then ], [ %B, %if.else ] %cmp17 = icmp sgt i32 %N.0, 0 br i1 %cmp17, label %for.body.preheader, label %for.end for.body.preheader: ; preds = %if.end %0 = icmp ult i32 %B, %A <<<<< This two instruction %1 = select i1 %0, i32 %B, i32 %A <<<<< can be replaced with %N.0 phi %2 = add i32 %1, -1 %3 = zext i32 %2 to i64 %4 = add nuw nsw i64 %3, 1 %scevgep = getelementptr i32, i32* %P, i64 %4 br label %for.end for.end: %P.addr.0.lcssa = phi i32* [ %P, %if.end ], [ %scevgep, %for.body.preheader ] ret i32* %P.addr.0.lcssa Code without select-like-phi recognition: if.end: ; preds = %if.else, %if.then %N.0 = phi i32 [ %A, %if.then ], [ %B, %if.else ] %cmp17 = icmp sgt i32 %N.0, 0 %0 = add i32 %N.0, -1 %1 = zext i32 %0 to i64 %2 = add nuw nsw i64 %1, 1 %scevgep = getelementptr i32, i32* %P, i64 %2 %P.addr.0.lcssa = select i1 %cmp17, i32* %scevgep, i32* %P ret i32* %P.addr.0.lcssa -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs