[llvm] c29522d - [TargetLowering] prepareUREMEqFold/prepareSREMEqFold - account for non legal shift types

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon May 17 03:03:38 PDT 2021


Author: Simon Pilgrim
Date: 2021-05-17T11:03:27+01:00
New Revision: c29522d6489adf85e0bf75fff7bdcf8b12b1b6e5

URL: https://github.com/llvm/llvm-project/commit/c29522d6489adf85e0bf75fff7bdcf8b12b1b6e5
DIFF: https://github.com/llvm/llvm-project/commit/c29522d6489adf85e0bf75fff7bdcf8b12b1b6e5.diff

LOG: [TargetLowering] prepareUREMEqFold/prepareSREMEqFold - account for non legal shift types

Ensure we tell getShiftAmountTy that we're working with pre-legalized types to prevent cases where the (legalized) shift type can no longer handle the (non-legalized) type width.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34366

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
    llvm/test/CodeGen/X86/urem-seteq.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 2df2877d37c5..53b3bcbb42ab 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -5455,7 +5455,7 @@ TargetLowering::prepareUREMEqFold(EVT SETCCVT, SDValue REMNode,
 
   EVT VT = REMNode.getValueType();
   EVT SVT = VT.getScalarType();
-  EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout());
+  EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout(), !DCI.isBeforeLegalize());
   EVT ShSVT = ShVT.getScalarType();
 
   // If MUL is unavailable, we cannot proceed in any case.
@@ -5699,7 +5699,7 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
 
   EVT VT = REMNode.getValueType();
   EVT SVT = VT.getScalarType();
-  EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout());
+  EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout(), !DCI.isBeforeLegalize());
   EVT ShSVT = ShVT.getScalarType();
 
   // If we are after ops legalization, and MUL is unavailable, we can not

diff  --git a/llvm/test/CodeGen/X86/urem-seteq.ll b/llvm/test/CodeGen/X86/urem-seteq.ll
index 1a16cf99b317..21aed941b06a 100644
--- a/llvm/test/CodeGen/X86/urem-seteq.ll
+++ b/llvm/test/CodeGen/X86/urem-seteq.ll
@@ -356,3 +356,36 @@ define i32 @test_urem_allones(i32 %X) nounwind {
   %ret = zext i1 %cmp to i32
   ret i32 %ret
 }
+
+; Check illegal types.
+
+; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34366
+define void @ossfuzz34366() {
+; X86-LABEL: ossfuzz34366:
+; X86:       # %bb.0:
+; X86-NEXT:    movl (%eax), %eax
+; X86-NEXT:    movl %eax, %ecx
+; X86-NEXT:    andl $2147483647, %ecx # imm = 0x7FFFFFFF
+; X86-NEXT:    orl %eax, %ecx
+; X86-NEXT:    orl %eax, %ecx
+; X86-NEXT:    orl %eax, %ecx
+; X86-NEXT:    orl %eax, %ecx
+; X86-NEXT:    sete (%eax)
+; X86-NEXT:    retl
+;
+; X64-LABEL: ossfuzz34366:
+; X64:       # %bb.0:
+; X64-NEXT:    movq (%rax), %rax
+; X64-NEXT:    movabsq $9223372036854775807, %rcx # imm = 0x7FFFFFFFFFFFFFFF
+; X64-NEXT:    andq %rax, %rcx
+; X64-NEXT:    orq %rax, %rcx
+; X64-NEXT:    orq %rax, %rcx
+; X64-NEXT:    orq %rax, %rcx
+; X64-NEXT:    sete (%rax)
+; X64-NEXT:    retq
+  %L10 = load i448, i448* undef, align 4
+  %B18 = urem i448 %L10, -363419362147803445274661903944002267176820680343659030140745099590319644056698961663095525356881782780381260803133088966767300814307328
+  %C13 = icmp ule i448 %B18, 0
+  store i1 %C13, i1* undef, align 1
+  ret void
+}


        


More information about the llvm-commits mailing list