llvm.org GIT mirror llvm / 6709348
[ValueTracking] allow non-canonical shuffles when computing signbits This possibility is noted in D53987 for a different case, so we need to adjust the existing code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345988 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 10 months ago
2 changed file(s) with 30 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
25102510 // extended, shifted, etc).
25112511 return ComputeNumSignBits(U->getOperand(0), Depth + 1, Q);
25122512
2513 case Instruction::ShuffleVector:
2513 case Instruction::ShuffleVector: {
25142514 // If the shuffle mask contains any undefined elements, that element of the
25152515 // result is undefined. Propagating information from a source operand may
25162516 // not be correct in that case, so just bail out.
25172517 if (cast(U)->getMask()->containsUndefElement())
25182518 break;
25192519
2520 assert((!isa(U->getOperand(0)) ||
2521 !isa(U->getOperand(1)))
2522 && "Should have simplified shuffle with 2 undef inputs");
2520 // If everything is undef, we can't say anything. This should be simplified.
2521 Value *Op0 = U->getOperand(0), *Op1 = U->getOperand(1);
2522 if (isa(Op0) && isa(Op1))
2523 break;
25232524
25242525 // Look through shuffle of 1 source vector.
2525 if (isa(U->getOperand(0)))
2526 return ComputeNumSignBits(U->getOperand(1), Depth + 1, Q);
2527 if (isa(U->getOperand(1)))
2528 return ComputeNumSignBits(U->getOperand(0), Depth + 1, Q);
2526 if (isa(Op0))
2527 return ComputeNumSignBits(Op1, Depth + 1, Q);
2528 if (isa(Op1))
2529 return ComputeNumSignBits(Op0, Depth + 1, Q);
25292530
25302531 // TODO: We can look through shuffles of 2 sources by computing the minimum
25312532 // sign bits for each operand (similar to what we do for binops).
25322533 break;
2534 }
25332535 }
25342536
25352537 // Finally, if we can prove that the top bits of the result are 0's or 1's,
493493 EXPECT_EQ(ComputeNumSignBits(RVal, M->getDataLayout()), 1u);
494494 }
495495
496 // No guarantees for canonical IR in this analysis, so this just bails out.
497 TEST(ValueTracking, ComputeNumSignBits_Shuffle) {
498 StringRef Assembly = "define <2 x i32> @f() { "
499 " %val = shufflevector <2 x i32> undef, <2 x i32> undef, <2 x i32> "
500 " ret <2 x i32> %val "
501 "} ";
502
503 LLVMContext Context;
504 SMDiagnostic Error;
505 auto M = parseAssemblyString(Assembly, Error, Context);
506 assert(M && "Bad assembly?");
507
508 auto *F = M->getFunction("f");
509 assert(F && "Bad assembly?");
510
511 auto *RVal =
512 cast(F->getEntryBlock().getTerminator())->getOperand(0);
513 EXPECT_EQ(ComputeNumSignBits(RVal, M->getDataLayout()), 1u);
514 }
515
496516 TEST(ValueTracking, ComputeKnownBits) {
497517 StringRef Assembly = "define i32 @f(i32 %a, i32 %b) { "
498518 " %ash = mul i32 %a, 8 "