[PATCH] D28485: [ValueTracking] recognize a 'not' of an assumed condition as false

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 15:02:24 PST 2017


On Mon, Jan 9, 2017 at 4:00 PM, Daniel Berlin <dberlin at dberlin.org> wrote:

>
>
> On Mon, Jan 9, 2017 at 3:00 PM, Sanjay Patel <spatel at rotateright.com>
> wrote:
>
>> Hi Daniel -
>>
>> [Not sure if you meant to only reply to me;
>>
>
> Nope, just hit the wrong button :)
>
>
>> I can reply to the list with the same message if that's ok with you.]
>>
>> Go for it.
>
>

I didn't mean for the last mail to be an illustration of 'it's easier to
ask for forgiveness than permission', but I accidentally had the list on
already. :)




> I don't think we handle the cases you're thinking of in any pass:
>>
>> define i1 @deduce_icmp_from_assume(i8 %a, i8 %b) {
>>   %eqcond = icmp eq i8 %a, %b
>>   call void @llvm.assume(i1 %eqcond)
>>   %ltcond = icmp slt i8 %a, %b
>>   ret i1 %ltcond
>> }
>>
>> 'opt -O2' has no effect on this example.
>>
>> Sigh.
>
>
>>
>> On Mon, Jan 9, 2017 at 3:43 PM, Daniel Berlin <dberlin at dberlin.org>
>> wrote:
>>
>>> Do we already handle that  > and < of an assumed equality is false?
>>>
>>> IE a == b ==true  -> a < b == false
>>> a == b ==true  -> a > b == false
>>>
>>> and the inverses?
>>>
>>> a < b == true -> a == b ==false
>>> a < b == true -> a != b == true
>>>
>>>
>>> On Mon, Jan 9, 2017 at 2:37 PM, Sanjay Patel via Phabricator via
>>> llvm-commits <llvm-commits at lists.llvm.org> wrote:
>>>
>>>> spatel created this revision.
>>>> spatel added reviewers: efriedma, majnemer, hfinkel.
>>>> spatel added a subscriber: llvm-commits.
>>>> Herald added a subscriber: mcrosier.
>>>>
>>>> I think this is a logical extension of the current checks in
>>>> computeKnownBitsFromAssume(). Ie, it has negligible cost for the added
>>>> functionality. But let me know if we need to re-think the whole approach.
>>>>
>>>> This is the reason I didn't have the canonical xor-form of 'not' in the
>>>> test case for https://reviews.llvm.org/D28337 - it doesn't work
>>>> without this change.
>>>>
>>>>
>>>> https://reviews.llvm.org/D28485
>>>>
>>>> Files:
>>>>   lib/Analysis/ValueTracking.cpp
>>>>   test/Transforms/InstCombine/assume.ll
>>>>
>>>>
>>>> Index: test/Transforms/InstCombine/assume.ll
>>>> ===================================================================
>>>> --- test/Transforms/InstCombine/assume.ll
>>>> +++ test/Transforms/InstCombine/assume.ll
>>>> @@ -176,13 +176,13 @@
>>>>    ret i32 %lnot.ext
>>>>  }
>>>>
>>>> -; FIXME: If the 'not' of a condition is known true, then the condition
>>>> must be false.
>>>> +; If the 'not' of a condition is known true, then the condition must
>>>> be false.
>>>>
>>>>  define i1 @assume_not(i1 %cond) {
>>>>  ; CHECK-LABEL: @assume_not(
>>>>  ; CHECK-NEXT:    [[NOTCOND:%.*]] = xor i1 [[COND:%.*]], true
>>>>  ; CHECK-NEXT:    call void @llvm.assume(i1 [[NOTCOND]])
>>>> -; CHECK-NEXT:    ret i1 [[COND]]
>>>> +; CHECK-NEXT:    ret i1 false
>>>>  ;
>>>>    %notcond = xor i1 %cond, true
>>>>    call void @llvm.assume(i1 %notcond)
>>>> Index: lib/Analysis/ValueTracking.cpp
>>>> ===================================================================
>>>> --- lib/Analysis/ValueTracking.cpp
>>>> +++ lib/Analysis/ValueTracking.cpp
>>>> @@ -544,10 +544,11 @@
>>>>
>>>>      Value *Arg = I->getArgOperand(0);
>>>>
>>>> -    if (Arg == V && isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
>>>> +    if ((Arg == V || match(Arg, m_Not(m_Specific(V)))) &&
>>>> +        isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
>>>>        assert(BitWidth == 1 && "assume operand is not i1?");
>>>> -      KnownZero.clearAllBits();
>>>> -      KnownOne.setAllBits();
>>>> +      KnownZero = Arg == V ? 0 : -1;
>>>> +      KnownOne = Arg == V ? -1 : 0;
>>>>        return;
>>>>      }
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> llvm-commits mailing list
>>>> llvm-commits at lists.llvm.org
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170109/f20807ed/attachment.html>


More information about the llvm-commits mailing list