[llvm] r364915 - [InstCombine] Shift amount reassociation: fixup constantexpr handling (PR42484)
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 05:54:48 PDT 2019
Author: lebedevri
Date: Tue Jul 2 05:54:48 2019
New Revision: 364915
URL: http://llvm.org/viewvc/llvm-project?rev=364915&view=rev
Log:
[InstCombine] Shift amount reassociation: fixup constantexpr handling (PR42484)
I was actually wondering if there was some nicer way than m_Value()+cast,
but apparently what i was really "subconsciously" thinking about
was correctness issue.
hasNoUnsignedWrap()/hasNoUnsignedWrap() exist for Instruction,
not for BinaryOperator, so let's just use m_Instruction(),
thus both avoiding a cast, and a crash.
Fixes https://bugs.llvm.org/show_bug.cgi?id=42484,
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=15587
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/trunk/test/Transforms/InstCombine/shift-amount-reassociation.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp?rev=364915&r1=364914&r2=364915&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp Tue Jul 2 05:54:48 2019
@@ -29,12 +29,12 @@ static Instruction *
reassociateShiftAmtsOfTwoSameDirectionShifts(BinaryOperator *Sh0,
const SimplifyQuery &SQ) {
// Look for: (x shiftopcode ShAmt0) shiftopcode ShAmt1
- Value *X, *ShAmt1, *Sh1Value, *ShAmt0;
+ Value *X, *ShAmt1, *ShAmt0;
+ Instruction *Sh1;
if (!match(Sh0, m_Shift(m_CombineAnd(m_Shift(m_Value(X), m_Value(ShAmt1)),
- m_Value(Sh1Value)),
+ m_Instruction(Sh1)),
m_Value(ShAmt0))))
return nullptr;
- auto *Sh1 = cast<BinaryOperator>(Sh1Value);
// The shift opcodes must be identical.
Instruction::BinaryOps ShiftOpcode = Sh0->getOpcode();
Modified: llvm/trunk/test/Transforms/InstCombine/shift-amount-reassociation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/shift-amount-reassociation.ll?rev=364915&r1=364914&r2=364915&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/shift-amount-reassociation.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/shift-amount-reassociation.ll Tue Jul 2 05:54:48 2019
@@ -154,6 +154,21 @@ define i32 @t11_shl_nsw_flag_preservatio
ret i32 %t3
}
+; Reduced from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=15587
+ at X = external global i32
+define i64 @constantexpr() {
+; CHECK-LABEL: @constantexpr(
+; CHECK-NEXT: ret i64 0
+;
+ %A = alloca i64
+ %L = load i64, i64* %A
+ %V = add i64 ptrtoint (i32* @X to i64), 0
+ %B2 = shl i64 %V, 0
+ %B4 = ashr i64 %B2, %L
+ %B = and i64 undef, %B4
+ ret i64 %B
+}
+
; No one-use tests since we will only produce a single instruction here.
; Negative tests
More information about the llvm-commits
mailing list