[PATCH] Fix crash in loop idiom recognizer
Pete Cooper
peter_cooper at apple.com
Mon Jul 13 14:26:08 PDT 2015
Thanks Hal, and sorry for the delay in committing.
r242068.
Pete
> On Jul 8, 2015, at 6:36 PM, Hal Finkel <hfinkel at anl.gov> wrote:
>
> LGTM.
>
> -Hal
>
> ----- Original Message -----
>> From: "Pete Cooper" <peter_cooper at apple.com>
>> To: "llvm-commits" <llvm-commits at cs.uiuc.edu>
>> Sent: Wednesday, July 8, 2015 1:35:38 PM
>> Subject: [PATCH] Fix crash in loop idiom recognizer
>>
>>
>>
>> Hi all
>>
>> When spotting that a loop can use ctpop, we were incorrectly
>> replacing all uses of a value with a value derived from ctpop.
>>
>> The bug here was exposed because we were replacing a use prior to the
>> ctpop with the ctpop value and so we have a use before def, i.e., we
>> changed
>>
>> %tobool.5 = icmp ne i32 %num, 0
>> store i1 %tobool.5, i1* %ptr
>> br i1 %tobool.5, label %for.body.lr.ph, label %for.end
>>
>> to
>>
>> store i1 %1, i1* %ptr
>> %0 = call i32 @llvm.ctpop.i32(i32 %num)
>> %1 = icmp ne i32 %0, 0
>> br i1 %1, label %for.body.lr.ph, label %for.end
>>
>> Even if we inserted the ctpop so that it dominates the store here,
>> that would still be incorrect. The store doesn’t want the result of
>> ctpop.
>>
>> The fix is very simple, and involves replacing only the branch
>> condition with the ctpop instead of all uses.
>>
>> Cheers,
>> Pete
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
> --
> Hal Finkel
> Assistant Computational Scientist
> Leadership Computing Facility
> Argonne National Laboratory
More information about the llvm-commits
mailing list