SimplifyDemandedVectorElts' handling of undef
| Bugzilla Link | 40091 |
| Resolution | FIXED |
| Resolved on | Dec 19, 2018 07:56 |
| Version | trunk |
| OS | Linux |
| CC | @RKSimon,@rotateright |
| Fixed by commit(s) | 349625 |
Extended Description
;target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" ;target triple = "aarch64-arm-none-eabi"
define i64 @test(i64 %aa) { entry: %a = bitcast i64 %aa to <1 x i64> %k = icmp sgt <1 x i64> %a, zeroinitializer %l = zext <1 x i1> %k to <1 x i64> %o = and <1 x i64> %l, %a %p = xor <1 x i64> %l, <i64 -1> %q = and <1 x i64> %p, <i64 81985529216486895> %r = or <1 x i64> %q, %o %s = bitcast <1 x i64> %r to <8 x i8> %t = shufflevector <8 x i8> %s, <8 x i8> %s, <8 x i32> <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3> %u = bitcast <8 x i8> %t to i64 ret i64 %u }
I would expect this to always return 0x8989898989898989 (the third element of that big constant in there), but currently returns 0xffffffffffffffff. It seems that the icmp is folded to undef (perhaps because it is not needed by demand bits), which then gets folded through into pretty much everything else (even through the zext). I am under the impression that undef should be bitwise (not vector-lane-wise), but I may be wrong there.
Bisects back to r349264, which adds OR handling to SimplifyDemandedVectorElts (but it looks like a bit of a knock-on effect).
Thanks! All the tests went green again.
Fixed in rL349625
Candidate Patch: https://reviews.llvm.org/D55883
The problem is that we have several place where zext (and zext_vector_inreg) fold an undef input into an undef output. For zero extensions this incorrect as the output should guaranteed to least have the new upper bits set to zero.
SimplifyDemandedVectorElts is the worst offender (and its the most likely to cause new undefs to appear) but DAGCombiner's tryToFoldExtendOfConstant has a similar issue.
Annotated:
define i64 @test(i64 %aa) { entry: %a = bitcast i64 %aa to <1 x i64> %k = icmp sgt <1 x i64> %a, zeroinitializer ; 0x0 or 0x1 %l = zext <1 x i1> %k to <1 x i64> ; 0x0000000000000000 or 0x0000000000000001 %o = and <1 x i64> %l, %a ; 0x0000000000000000 or 0x0000000000000001 %p = xor <1 x i64> %l, <i64 -1> ; 0xFFFFFFFFFFFFFFFF or 0xFFFFFFFFFFFFFFFE %q = and <1 x i64> %p, <i64 81985529216486895> ; 0x0123456789ABCDEF or 0x0123456789ABCDEE %r = or <1 x i64> %q, %o ; 0x0123456789ABCDEF or 0x0123456789ABCDEE %s = bitcast <1 x i64> %r to <8 x i8> ; <0xEF 0xCD 0xAB 0x89 0x67 0x45 0x23 0x01> or <0xEE 0xCD 0xAB 0x89 0x67 0x45 0x23 0x01> %t = shufflevector <8 x i8> %s, <8 x i8> %s, <8 x i32> <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3> ; <0x89> %u = bitcast <8 x i8> %t to i64 ; 0x8989898989898989 ret i64 %u }
vs reality:
test: // @test movi v0.2d, #0xffffffffffffffff fmov x0, d0 ret
assigned to @RKSimon