[LLVMdev] Is ConstantFoldConstantExpression meant to be idempotent?

Ben Karel
Thu, 26 Sep 2013 19:34:59 -0000

I noticed a change in LLVM's behavior between 3.2 and 3.3/ToT, but I'm
not
sure if it qualifies as a bug/regression or not.

The change is that in 3.3 and tip of trunk, calling
ConstantFoldConstantExpression on

    i64 and (i64 add (i64 add (i64 ptrtoint (i64* getelementptr (i64* null,
i32 1) to i64), i64 ptrtoint (i64* getelementptr (i64* null, i32 1) to
i64)), i64 15), i64 -16)

produces

    i64 and (i64 add (i64 ptrtoint (i64* getelementptr (i64* null, i32 1)
to i64), i64 23), i64 -16)

which, when passed back to ConstantFoldConstantExpression, gets boiled down
to

    i64 16


LLVM 3.2 returns a ConstantInt from the first call. I've attached a small
testcase which shows this behavior.

Is the fact that ConstantFoldConstantExpression does not produce a
"minimal" constant expression a bug, or are clients expected to
potentially
need to iterate folding to get a final result? I didn't see anything in
3.3's release notes about changes to constant folding behavior.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20130926/6a7717c6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t3.cpp
Type: text/x-c++src
Size: 1445 bytes
Desc: not available
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20130926/6a7717c6/attachment.cpp>