Hi,
We recently found a testcase showing that simplifications in
instcombine sometimes change the instruction without reducing the
instruction cost, but causing problems in TwoAddressInstruction pass.
And it looks like the problem is generic and other simplification may
have the same issue. I want to get some ideas about what is the best
way to fix such kind of problem.
The testcase:
----------------------------- a.ll ----------------------------------
@a = global i64 0, align 8
@b = global i32 0, align 8
define i32 @_Z25InternalUncompressAllTagsv(i16* %arrayidx) local_unnamed_addr {
entry:
%t1 = load i16, i16* %arrayidx, align 2
%conv.i = zext i16 %t1 to i32
%and.i = and i32 %conv.i, 255
%and7.i = and i32 %conv.i, 1792
%t3 = zext i32 %and7.i to i64
%t4 = load i64, i64* @a, align 8
%add.i = add i64 %t4, %t3
%cmp1 = icmp eq i64 %add.i, 1
%cmp2 = icmp ult i32 %and.i, 101
%bool = and i1 %cmp1, %cmp2
br i1 %bool, label %if.then, label %if.else, !prof !0
if.then: ; preds = %entry
%r1 = trunc i64 %add.i to i32
br label %return
if.else: ; preds = %entry
%r2 = and i32 %and.i, 31
store i32 %and.i, i32* @b, align 8
br label %return
return: ; preds = %if.else, %if.then
%ret = phi i32 [ %r1, %if.then ], [ %r2, %if.else ]
ret i32 %ret
}
!0 = !{!"branch_weights", i32 2000, i32 1}