[llvm-commits] [llvm] r170020 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCompares.cpp test/Transforms/InstCombine/icmp.ll
David Majnemer
david.majnemer at gmail.com
Sun Dec 16 12:59:54 PST 2012
The hope was that I could use it to find where clang might be using undefined behavior and see if it could be fixed.
Sent from my iPhone
On Dec 16, 2012, at 12:13 PM, Evan Cheng <evan.cheng at apple.com> wrote:
>
>
> On Dec 14, 2012, at 10:46 AM, David Majnemer <david.majnemer at gmail.com> wrote:
>
>> Is there a way for us to emit trap instructions if clang uses a left shift in an undefined mannor?
>
> That would be an overly user unfriendly behavior. People do write non-portable code sometimes. :)
>
> Evan
>
>>
>>
>> On Thu, Dec 13, 2012 at 6:39 AM, NAKAMURA Takumi <geek4civic at gmail.com> wrote:
>>> David, excuse me, I have reverted it in r170128 to unbreak selfhosting.
>>>
>>> It seems isKnownToBeAPowerOfTwo(X) assumes (1 << n) always non-zero.
>>> (It might be "non-zero, or undefined")
>>>
>>> FYI, http://bb.pgr.jp/builders/clang-3stage-x86_64-linux/builds/271
>>>
>>> I am investigating "undefined behavior" in clang.
>>>
>>> ...Takumi
>>>
>>> 2012/12/13 David Majnemer <david.majnemer at gmail.com>:
>>> > Author: majnemer
>>> > Date: Wed Dec 12 14:48:54 2012
>>> > New Revision: 170020
>>> >
>>> > URL: http://llvm.org/viewvc/llvm-project?rev=170020&view=rev
>>> > Log:
>>> > Simplify negated bit test
>>> >
>>> > Modified:
>>> > llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
>>> > llvm/trunk/test/Transforms/InstCombine/icmp.ll
>>> >
>>> > Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
>>> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=170020&r1=170019&r2=170020&view=diff
>>> > ==============================================================================
>>> > --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
>>> > +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Dec 12 14:48:54 2012
>>> > @@ -2034,6 +2034,15 @@
>>> > CI->countTrailingZeros()));
>>> > }
>>> >
>>> > + // Turn x&~y == 0 into x&y != 0 if x is a power of 2.
>>> > + Value *X = 0, *Y = 0;
>>> > + if (match(Op0, m_And(m_Value(X), m_Not(m_Value(Y)))) &&
>>> > + match(Op1, m_Zero()) && isPowerOfTwo(X, TD)) {
>>> > + return new ICmpInst(ICmpInst::ICMP_NE,
>>> > + Builder->CreateAnd(X, Y),
>>> > + Op1);
>>> > + }
>>> > +
>>> > break;
>>> > }
>>> > case ICmpInst::ICMP_NE: {
>>> > @@ -2071,6 +2080,15 @@
>>> > CI->countTrailingZeros()));
>>> > }
>>> >
>>> > + // Turn x&~y != 0 into x&y == 0 if x is a power of 2.
>>> > + Value *X = 0, *Y = 0;
>>> > + if (match(Op0, m_And(m_Value(X), m_Not(m_Value(Y)))) &&
>>> > + match(Op1, m_Zero()) && isPowerOfTwo(X, TD)) {
>>> > + return new ICmpInst(ICmpInst::ICMP_EQ,
>>> > + Builder->CreateAnd(X, Y),
>>> > + Op1);
>>> > + }
>>> > +
>>> > break;
>>> > }
>>> > case ICmpInst::ICMP_ULT:
>>> >
>>> > Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
>>> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=170020&r1=170019&r2=170020&view=diff
>>> > ==============================================================================
>>> > --- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
>>> > +++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Wed Dec 12 14:48:54 2012
>>> > @@ -677,3 +677,29 @@
>>> > ; CHECK-NEXT: ret i1 true
>>> > ret i1 %cmp
>>> > }
>>> > +
>>> > +define i1 @test67(i32 %A, i32 %B) {
>>> > + %neg = xor i32 %A, -1
>>> > + %shl = shl i32 1, %B
>>> > + %and = and i32 %shl, %neg
>>> > + %cmp = icmp ne i32 %and, 0
>>> > +; CHECK: @test67
>>> > +; CHECK-NEXT: %shl = shl i32 1, %B
>>> > +; CHECK-NEXT: %1 = and i32 %shl, %A
>>> > +; CHECK-NEXT: %cmp = icmp eq i32 %1, 0
>>> > +; CHECK-NEXT: ret i1 %cmp
>>> > + ret i1 %cmp
>>> > +}
>>> > +
>>> > +define i1 @test68(i32 %A, i32 %B) {
>>> > + %neg = xor i32 %A, -1
>>> > + %shl = shl i32 1, %B
>>> > + %and = and i32 %shl, %neg
>>> > + %cmp = icmp eq i32 %and, 0
>>> > +; CHECK: @test68
>>> > +; CHECK-NEXT: %shl = shl i32 1, %B
>>> > +; CHECK-NEXT: %1 = and i32 %shl, %A
>>> > +; CHECK-NEXT: %cmp = icmp ne i32 %1, 0
>>> > +; CHECK-NEXT: ret i1 %cmp
>>> > + ret i1 %cmp
>>> > +}
>>> >
>>> >
>>> > _______________________________________________
>>> > llvm-commits mailing list
>>> > llvm-commits at cs.uiuc.edu
>>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121216/7f1eea76/attachment.html>
More information about the llvm-commits
mailing list